admin管理员组文章数量:1288167
As you know, we can assign a "Category" to any post we write. We can also use a "Category" as link on the menu. Good!
By default, WordPress will display all your posts in all the categories on your front page.
However, how to prevent Wordpress displaying a "Category" type on the front page? Example, I have a post with a category name "Football". I don't want all posts with this category to be displayed on the front page, how to do that? I will access it only on the menu.
Thank
As you know, we can assign a "Category" to any post we write. We can also use a "Category" as link on the menu. Good!
By default, WordPress will display all your posts in all the categories on your front page.
However, how to prevent Wordpress displaying a "Category" type on the front page? Example, I have a post with a category name "Football". I don't want all posts with this category to be displayed on the front page, how to do that? I will access it only on the menu.
Thank
Share Improve this question asked May 18, 2015 at 21:15 user73291user73291 11 bronze badge 2 |2 Answers
Reset to default 1You can use pre_get_posts
Exclude categories on your main page
function exclude_category( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'cat', '-1,-1347' );
}
}
add_action( 'pre_get_posts', 'exclude_category' );
Try the Ultimate Category Excluder plugin, it does what you ask to not show on the front page, plus has options to exclude from your RSS Feed, searches, or as an archive.
https://wordpress/plugins/ultimate-category-excluder/
A different approach might be to not use recent posts on your front page, but make a static Page your front view as a welcome to the site. You can use something like Display Posts plugin to put posts from categories you want on the front or in a footer/sidebar https://wordpress/plugins/display-posts-shortcode/
本文标签: categoriesHow to not display a category post on blog page
版权声明:本文标题:categories - How to not display a category post on blog page? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741337035a2373094.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
pre_get_posts
in codex. – Milo Commented May 18, 2015 at 21:21