繁体   English   中英

从博客页面中排除带有特定标签的帖子

[英]Excluding posts with certain tag from blogpage

我已经通过编辑function.php成功地从博客页面中排除了某些类别,但是我似乎无法从博客中排除所有标签ID为113的帖子。 谁能指出我应使用的代码来帮助我? 在此先感谢您,最好的问候,

您可以使用以下代码:

if(!has_tag(113))
{
  //Display your posts
}

上面的代码应在Wordpress循环内使用。

==>为了过滤在functions.php中的帖子,您可以使用“ pre_get_posts ”钩子:

function exclude_tag($query)
{
    if ($query->is_main_query()) {
        $query->set('tag__not_in', array( '113' ));
    }
}
add_action('pre_get_posts', 'exclude_tag');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM