Php 随机邮购-Wordpress

Php 随机邮购-Wordpress,php,wordpress,Php,Wordpress,在单个帖子上,我在循环外显示其他类似的帖子 $posts = get_posts('numberposts=200&category='. $category->term_id); foreach($posts as $post) : 尝试添加 query_posts($query_string . '&orderby=rand'); 但不管我怎么做,都不要随机排序,问题是我没有把它放在get_帖子的第一位,比如 $posts = get_posts('orderby=

在单个帖子上,我在循环外显示其他类似的帖子

$posts = get_posts('numberposts=200&category='. $category->term_id);
foreach($posts as $post) :
尝试添加

query_posts($query_string . '&orderby=rand');

但不管我怎么做,都不要随机排序,问题是我没有把它放在get_帖子的第一位,比如

$posts = get_posts('orderby=rand&numberposts=200&category='. $category->term_id);
foreach($posts as $post) :
试试这个:

<?php
$args = array( 'posts_per_page' => 5, 'orderby' => 'rand' );
$rand_posts = get_posts( $args );

foreach ( $rand_posts as $post ) :  
  setup_postdata( $post ); ?> 
  <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> 
<?php 
endforeach; 

wp_reset_postdata(); ?>

  • 你可以看到法典: