网站优化

网站优化

Products

当前位置:首页 > 网站优化 >

修改显示哪些Wordpress类别

GG网络技术分享 2025-03-18 16:12 11


问题描述:

I\'m building a bespoke Wordpress theme for a periodical. I have a category set up that basically marks an article as \"featured,\" making them appear on the homepage. I\'d like for this category to not appear when browsing the site, however, as it\'s meant for the magazine\'s staff to be able to control what\'s on the homepage, rather than be used as a tool for user\'s to search with.

Since the_category(); will return all categories, I need help building a php loop that will display categories while skipping this one. A post will only ever have one category, unless this second one is applied. I also think building a function that could be referenced several times across the site would be the most efficient way of handling this.

If there\'s an even simpler method to reach the same outcome, feel free to point that out as well. I\'d just like to keep my plugin dependencies minimal. Thanks for your assistance!

图片转代码服务由CSDN问答提供

感谢您的意见,我们尽快改进~

功能建议

我正在为期刊制作一个定制的Wordpress主题。 我有一个类别设置基本上将文章标记为“特色”,使它们出现在主页上。 我希望这个类别在浏览网站时不会出现,因为它意味着杂志的工作人员能够控制主页上的内容,而不是用作用户搜索的工具。</ p >

由于the_category(); 将返回所有类别,我需要帮助构建一个PHP循环,将显示类别,同时跳过这一个。 除非第二个类别被应用,否则帖子将只有一个类别。 我还认为构建一个可以在整个站点上多次引用的函数将是处理此问题的最有效方法。</ p>

如果有更简单的方法可以达到相同的结果,请随意 也指出了这一点。 我只想保持我的插件依赖性最小化。 谢谢你的协助! </ p>

</ div>

网友观点:

After doing more research into my options for developing with Wordpress, I\'ve found that using a custom post type will work far better than filing these posts under a category. Apologies for the confusing post.

###

You\'ll first have to find the id of the \\\"featured\\\" category.

Then find the php pages where the categories are displayed (I know they are in single.php for instance).

Once you\'ve done that, just add a if/else statement to display categories only if the category isn\'t \\\"featured\\\":

<?php 

if(in_category(\'idOfFeaturedCategory\')){} // For this category, do not echo anything

else {?>

<p>Catégorie(s) : <strong><?php the_category(\',\'); ?></strong></p> <!-- echo all the others categories -->

<?php

}

?>

标签: Wordpress主题

提交需求或反馈

Demand feedback