如何在查询中仅显示特定数量的帖子?

时间:2012-08-23 07:30:13

标签: php wordpress

我正在尝试查询由Wordpress支持的网站主页上的3篇最新帖子:

    wp_reset_postdata();
    wp_reset_query();
    query_posts('showposts=3');
    rewind_posts();
    while (have_posts()) : the_post();
        // do stuff.
        the_title();
    endwhile;

但是,正在显示7个帖子。此外,并非所有这7个帖子都是最新帖子。在此查询之上,还有其他查询。

如您所见,我尝试重置帖子数据和查询数据无济于事。还有哪些其他因素会影响检索的帖子?

1 个答案:

答案 0 :(得分:2)

请确保您不将该代码放在另一个have_posts循环中。 这应该有效:

query_posts( array( 'posts_per_page' => 3, 'orderby' => 'date', 'order' => 'DESC' ) );
    while (have_posts()) : the_post();
        // do stuff.
        the_title();
    endwhile;
相关问题