黄聪

论SEO对人类的重要性,请看我的博客:hcsem.com

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

不显示置顶文章

$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();

 

只显示置顶文章

/* 获取所有置顶文章 */
$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();

 

posted on 2012-12-20 13:57  黄聪  阅读(559)  评论(0编辑  收藏  举报