【问题标题】:Wordpress random post inside while loop在while循环中的Wordpress随机帖子
【发布时间】:2013-07-03 08:37:03
【问题描述】:

我正在使用 while 循环

while (have_posts()) : the_post();

获取所有帖子并显示一个页面。如何随机发布帖子。但问题是,在我正在处理的页面中没有“查询”的迹象。我也尝试使用提到的一些解决方案,但没有结果。

【问题讨论】:

    标签: wordpress while-loop


    【解决方案1】:

    您可以通过这种方式使用query_posts($args) 更改主查询:

    // Alter the query
    query_posts( 'orderby=RAND' );
    
    while ( have_posts() ) : the_post();
    
        // Do your stuff inside the loop
    
    endwhile;
    
    // Reset the query
    wp_reset_query();
    

    【讨论】:

    • 感谢您的回复。我尝试了此解决方案,但并未显示所有帖子。
    猜你喜欢
    • 1970-01-01
    • 2012-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-29
    • 2020-12-15
    相关资源
    最近更新 更多