如何从wordpress的主页中删除特定类别中的帖子?我想按类别的名称或id或...
我使用循环来获取我的帖子,如下所示:
if (!have_posts()) : while (have_posts()) : the_post();非常感谢
发布于 2012-04-07 03:29:17
你可以使用这个函数,不需要知道你的cat-id是什么,只需要使用category-slug:
function exclude_category($query) {
if ( $query->is_front_page ) {
$category_ID1 = get_cat_id(category_slugA);
$category_ID2 = get_cat_id(category_slugB);
$query->set('cat',"-$category_ID1 -$category_ID2");
} return $query;
} add_filter('pre_get_posts', 'exclude_category');发布于 2012-04-05 22:27:32
你可以尝试使用这个插件: wordpress.org/extend/plugins/front-page-excluded-categories你也可以尝试将这个代码添加到你的‘functions.php’中:
<?php function excludeCat($query) { if ( $query->is_home ) { $query->set('cat', '-3,-5,-23'); } return $query; } add_filter('pre_get_posts', 'excludeCat'); ?> 其中-3、-5和-23是要删除的类别ids。
发布于 2012-04-06 08:58:56
我推荐Advanced Category Excluder。非常容易使用。几乎令人痛苦地易于使用。
https://stackoverflow.com/questions/10022305
复制相似问题