WordPress无插件实现随机文章

继续我的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里面。

转载自:沉睡海洋

本文地址:WordPress无插件实现随机文章

相关日志

4 Comments:

  1. 你的single页面挂的谁的广告啊?不稳定

    HuMeng said on: 2010年04月21日 3:00 下午
  2. 这个方法也不错啊;控制起来好控制吗?

    你的博客描述和博客名字给我留言。

    my site info:
    Rtrash|废纸篓
    取其精华,去其糟粕;www.rtrash.net

    废纸篓 said on: 2010年04月22日 1:36 上午
  3. 最近正在全面精简插件 这个对我很有用

    8路杂讯 said on: 2010年04月22日 1:54 上午
  4. 加进去后,显示不了了。!

    集趣 said on: 2010年04月22日 11:33 上午

Post a Comment

Your email is never published nor shared. Required fields are marked *

Type your comment out: