繁体   English   中英

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

[英]How can I show only a certain number of posts in a query?

我正在尝试查询由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个帖子都是最新帖子。 在此查询上方,还有其他查询。

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

请确保不要将该代码放在另一个have_posts循环中。 这应该工作:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM