wordpress 自定义查询 query_posts

转载自:http://blog.sina.com.cn/s/blog_a225d3970101331q.html

query_posts函数仅用于修改主页循环(Loop),而不是一种在页面上生成次级循环的手段。如果你希望在主循环外另外生成循环,应该新建 独立的WP_Query对 象,用这些对象生成循环。在主循环外的循环上使用query_posts会导致主循环运行偏差,并可能在页面上显示出你不希望看到的内容。

query_posts函数会改写并取代页面的主查询。为谨慎起见,请不要将query_posts用作其它用途。

 

(from wordpress GDT 主题)



$prologue_query = new WP_Query('showposts=' . $num_posts . '&post_status=publish&tag__not_in=44');

    ob_start();

    while ($prologue_query->have_posts()) : $prologue_query->the_post();

        $current_user_id = get_the_author_ID( );

        $postdate = get_gmt_from_date( get_the_time( 'Y-m-d H:i:s' ) );
        if (  $postdate <=  $load_time ) continue;
        //if ( get_the_time( 'Y-m-d H:i:s' ) <=  $load_time ) continue;

        $number_of_new_posts++;

        if ( $frontpage ) {

?>
<?php

}

    endwhile;

 

 

posted @ 2013-03-25 15:10  hurner  Views(316)  Comments(0Edit  收藏  举报