WordPress 如何过滤Recent Posts中的分类

有些分类不想出现在WordPress的Recent Posts中,如何处理呢?

其实方法很简单,只需要在主题的functions.php文件尾部添加如下代码即可:

function filter_widget_posts_args( $args ) {
    $exclude = "要排除的分类ID";
    $args["category__not_in"] = $exclude;
    return $args;
};
add_filter( 'widget_posts_args', 'filter_widget_posts_args' );

如果要排除的是多个分类,如1,2,则$exclude = “array(1,2)”

 

未经允许不得转载:阿藏博客 » WordPress 如何过滤Recent Posts中的分类

赞 (0) 打赏