从类别循环中以随机顺序显示帖子


Show posts in random order from category loop

我在Wordpress中有一个类别循环,它根据类别输出不同的标记。这一切都很好,现在我需要帖子以随机顺序显示。我使用了"orderby => "rand",但这只会随机化每个类别中的帖子,即类别本身仍然按时间顺序输出。我不确定该怎么做,并希望得到任何帮助。

法典:

<?php
$categories = get_categories();
  foreach($categories as $category) {
  $args=array(
  'category__in' => array($category->term_id),
  'caller_get_posts'=>1,
  'orderby' => 'rand'
);
$posts=get_posts($args);
  shuffle($posts);
  if ($posts) {
    foreach($posts as $post) {
      setup_postdata($post); 
                   echo "<li class='cat-{$category->term_id}'><a href='".get_permalink()."'>".get_the_post_thumbnail()."</a></li><!-- 
                   -->";
    } 
  } 
} 
?>  

更新:根据伊曼纽尔的建议解决 - 添加随机播放($categories);

使用 shuffle( $array ); 在数组中随机排列元素。

$categories = get_categories();
shuffle( $categories );
foreach( $categories as $category ){
    //Your stuff
}

希望对您有所帮助!