我在两页中使用了“最近的帖子”,我需要从这两页中限制一些特定类别的帖子。我在functions.php中添加了下面的代码并保存了下来。但预期的结果不会到来。主页(ID-12)和诗歌页面(ID-8)是我添加的限制772和152是我想限制的页面的类别ID。
function excludeCat($query) {
$page = get_query_var('paged', 1);
$exclude = [
12 => '-772',
8 => '-152'
];
if ($query->is_home && isset($exclude[$page])) {
$query->set('cat', $exclude[$page]);
}
return $query;
}
add_filter('pre_get_posts', 'excludeCat');请就密码提出建议
发布于 2019-06-25 01:37:59
只需查看下面的代码并用"functions.php“file.It编写它就可以帮助您。
add_filter( 'widget_posts_args', 'my_widget_posts_args');
function my_widget_posts_args($args) {
return array(
'cat' => array(-5,-4) // pass the term id of category which you want to exclude with prefix "-".
);
}https://stackoverflow.com/questions/56507015
复制相似问题