wordpress中显示随机文章
2010-12-27 13:12codeif.com
1.使用get_posts生成随机文章
<?php
$rand_posts = get_posts('numberposts=10&orderby=rand');
foreach( $rand_posts as $post ) :
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
2.使用随处可见的query_psots
<?php
query_posts('showposts=10&orderby=rand');
if ( have_posts() ) : while ( have_posts() ) : the_post();
?>
<li><em><?php echo $j++;?></em><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php
endwhile; else:
?>
没有可显示的文章
<?php
endif;
wp_reset_query();
?>
