- 加入我的QQ群
- 关注我的百家号
扫描下面的二维码,“关注”我的百家号。
前面文章中我们了解了“wordpress怎样调用最新文章”,本节我们来看看wordpress怎样调用随机文章。
wordpress怎样调用随机文章方法一:foreach循环
<?php
$rand_posts = get_posts('numberposts=10&orderby=rand');
foreach( $rand_posts as $post ) :
?>
<!–下面是你想自定义的Loop–>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
wordpress怎样调用随机文章方法二:while循环
<?php query_posts('posts_per_page=10&caller_get_posts=1&orderby=rand'); ?>
<?php while (have_posts()) : the_post(); ?>
<li>
<a target="_blank" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="title"><?php the_title(); ?></a>
</li>
<?php endwhile; ?>
这2种方法都能实随机文章的调用。