wordpress显示某分类下的随机文章
更新时间:2012-08-27 16:25 作者:小兵点击:
如果你只是想在某个位置显示5篇随机文章可以用下面的代码调用:
1
2
|
<?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篇随机文章可以用下面的代码调用:
1
2
3
4
|
<?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; ?>
|
showposts=5表示随机显示文章数目
cat=1表示随机显示的那个分类下的文章ID
orderby=rand表示显示的排序方式随机
|
------分隔线----------------------------