WordPress

WordPress首页主循环中排除置顶文章的代码

把下面的代码添加到当前主题的functions.php文件,保存即可

function exclude_sticky_posts($query){
    if ( is_admin() || ! $query->is_main_query() )
	    return;
    if ( $query->is_home() && $query->is_main_query() ) {
        $query->set( 'ignore_sticky_posts', 1 );
    }
}  
add_action('pre_get_posts','exclude_sticky_posts');

如果要排除其它页面的,就把代码中的is_home()改一下即可。

转载自:原文链接

龙Ge

龙Ge

前端•不会,后端•是啥

喜欢在深夜写一点没用的代码。

评论

0

发表评论

邮箱不会被公开。
验证码