簡體   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