我使用bellow函数(感谢@helgatheviking!)到exclude categories 从wordpress循环。它工作得很好-选定类别的帖子被排除在主博客列表页面、类别列表页面和存档的循环之外,but not 来自最近的帖子,而不是侧边栏中最近的评论。如何扩展此代码对它们的作用?
add_action(\'pre_get_posts\', \'wpa_31553\' );
function wpa_31553( $wp_query ) {
//$wp_query is passed by reference. we don\'t need to return anything. whatever changes made inside this function will automatically effect the global variable
$excluded = array(272); //made it an array in case you need to exclude more than one
// only exclude on the front end
if( !is_admin() ) {
set_query_var(\'category__not_in\', $excluded);
//which is merely the more elegant way to write:
//$wp_query->set(\'category__not_in\', $excluded);
}
}
UPDATE:有一点需要澄清的是,排除的类别还没有从categories小部件中消失。当我用鼠标点击打开它们时,这些类别中的所有帖子都消失了。我希望它们也从Categories小部件中消失。