随机发布的订单 - Wordpress

时间:2013-10-14 17:49:06

标签: php wordpress

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

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

尝试添加

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

但是我尝试不按随机顺序执行

2 个答案:

答案 0 :(得分:0)

问题是我没有把它放在get_posts中,如

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

答案 1 :(得分:0)

试试这个:

<?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(); ?>

你可以看到codex:

http://codex.wordpress.org/Template_Tags/get_posts