wordpress函数某分类下的随机文章

之前博客里面有一篇关于输出分类列表的文章,介绍的不是很具体,使用起来也有点小不方便,在此重新做一下修正:

如果你只是想在某个位置显示5篇随机文章可以用下面的代码调用:

<?php $rand_posts = get_posts('numberposts=5&orderby=rand');  foreach( $rand_posts as $post ) : ?>
<li><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>" ><?php the_title(); ?></a></li>
<?php endforeach; ?>

如果你只是想在某个位置显示某分类下的5篇随机文章可以用下面的代码调用:

<?php
query_posts('showposts=5&cat=1&orderby=rand');while(have_posts()) : the_post();?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
<?php endwhile; 
wp_reset_query();
?>