现在的位置: 首页 > 综合 > 正文

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

2011年06月28日 ⁄ 综合 ⁄ 共 524字 ⁄ 字号 评论关闭

不显示置顶文章

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

 

抱歉!评论已关闭.