WordPress无插件实现随机文章

2010年04月21日13:20:48 3 热度3,757 ℃

继续我的WordPress无插件修改之旅这个很简单了,只需要搞定get_posts函数就好了,具体代码如下:

 <h2>
  随机文章
</h2>
<ul>
      <?php
    $rand_posts = get_posts('numberposts=8&orderby=rand');
    foreach( $rand_posts as $post ) :
      ?>
            <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
            <?php endforeach; ?>
</ul>

看着合适的地方加就可以了,可以加到Sidebar里面或者文章Single里面。

本文最后更新于:2020-05-24 20:43