wordpress设置不显示(只显示)置顶文章


不显示置顶文章html

复制代码
$paged = get_query_var( 'page' ) ? get_query_var( 'page' ) : 1;
$sticky = get_option( 'sticky_posts' );
$args = array(
    'ignore_sticky_posts' => 1,//忽略sticky_posts,不置顶,可是输出置顶文章
    'post__not_in' => $sticky,//排除置顶文章,不输出
    'paged' => $paged
);
query_posts( $args );
wp_reset_query();
复制代码

 

只显示置顶文章markdown

复制代码
/* 获取全部置顶文章 */
$sticky = get_option( 'sticky_posts' );
/* 对这些文章排序, 日期最新的在最上 */
rsort( $sticky ); /* 获取5篇文章 */
$sticky = array_slice( $sticky, 0, 5 );
/* 输出这些文章 */
query_posts( array( 'post__in' => $sticky, 'ignore_sticky_posts' => 1 ) );
while ( have_posts() ) : the_post();  
/* 输出内容 */
endwhile;
wp_reset_query();


本文转自黄聪博客园博客,原文连接:http://www.cnblogs.com/huangcong/archive/2012/12/20/2826342.html,如需转载请自行联系原做者