admin管理员组文章数量:1432378
We have a lot of blog post categories, and posts belonging to all but one category should show on the blog page. The other category should show on the Case Studies
page.
The solutions I've found make a global exclusion using functions.php
, which would break the Case Studies
sort.
I'm comfortable working with PHP but not sure how I would go about excluding the category on just one page.
Edit: Here is an example of category exclusion that I think would globally exclude category with ID of 1
in functions.php:
function exclude_category($query) {
$query->set('cat','-1');
return $query;
}
add_filter('pre_get_posts','exclude_category');
Below is one that is specific to a feed
page. Does it know to exclude it on the feed
page because feed
is the slug of the page to exclude for?
function exclude_category($query) {
if ($query->is_feed) {
$query->set('cat','-1');
}
return $query;
}
add_filter('pre_get_posts','exclude_category');
We have a lot of blog post categories, and posts belonging to all but one category should show on the blog page. The other category should show on the Case Studies
page.
The solutions I've found make a global exclusion using functions.php
, which would break the Case Studies
sort.
I'm comfortable working with PHP but not sure how I would go about excluding the category on just one page.
Edit: Here is an example of category exclusion that I think would globally exclude category with ID of 1
in functions.php:
function exclude_category($query) {
$query->set('cat','-1');
return $query;
}
add_filter('pre_get_posts','exclude_category');
Below is one that is specific to a feed
page. Does it know to exclude it on the feed
page because feed
is the slug of the page to exclude for?
function exclude_category($query) {
if ($query->is_feed) {
$query->set('cat','-1');
}
return $query;
}
add_filter('pre_get_posts','exclude_category');
Share
Improve this question
edited Apr 4, 2019 at 19:37
NAMS
asked Apr 3, 2019 at 20:14
NAMSNAMS
1013 bronze badges
3
|
1 Answer
Reset to default 0I resolved this by creating a custom page template for my Blog page to exclude posts of the category Case Studies
.
I followed this tutorial more or less and was successful adding the category exclusion code in my original post to exclude the case studies.
本文标签: categoriesExclude posts in a category on one page but show those posts on a different page
版权声明:本文标题:categories - Exclude posts in a category on one page but show those posts on a different page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745595356a2665445.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
category-case-studies.php
) or are you using the defaultcategory.php
orarchive.php
or falling back onindex.php
? – jsmod Commented Apr 3, 2019 at 20:26pre_get_posts
. – jdm2112 Commented Apr 3, 2019 at 23:58