取消置顶,按普通方式输出文章
<?php $args = array( 'posts_per_page' => 10, //每页显示10篇文章 'ignore_sticky_posts' => 1 //取消文章置顶 ); $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?> //在这里插入循环内部代码 <?php endwhile; ?> <?php endif; ?>
'ignore_sticky_posts' => 1 就是关键参数,取消文章置顶(即不在顶部显示),按照普通方式输出文章
彻底排除置顶文章,不输出
<?php $the_query = new WP_Query( array( 'post__not_in' => get_option( 'sticky_posts' ) ) ); if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?> //在这里插入循环内部代码 <?php endwhile; ?> <?php endif; ?>
'post__not_in' => get_option( 'sticky_posts' ) 是关键参数,彻底排除置顶文章(凡是置顶文章都不输出)。假如你在已经在首页的其他地方(比如幻灯中)显示了置顶文章,那么,接下来的主循环中排除置顶文章,这样就可以避免重复显示。
龙哥 发表于 1年前 (2021-03-20),共660字
版权声明:①欢迎转载但请注明出处。②如涉及版权联系(izhailong#qq.com)删除!
转载请注明:在 WordPress 循环中排除置顶文章 || https://www.izhailong.com/273.html
本文由:版权声明:①欢迎转载但请注明出处。②如涉及版权联系(izhailong#qq.com)删除!
转载请注明:在 WordPress 循环中排除置顶文章 || https://www.izhailong.com/273.html
暂无评论