宅事

记录闲时弄的小东西

Habari中显示"最近文章"

接上面一篇文章,这篇讲怎样增加"最近发表的文章"这个功能.同样先在theme.php的add_template_vars函数中加入:

  1. $this->assign('recent_posts',
  2.        Posts::get( array('limit'=>5, 'status'=>'published',
  3.        'orderby'=>'pubdate DESC' ) ) );

修改"5"为你想要显示的数目.

接着编辑你想要增加这功能的地方,比如侧边栏 sidebar.php,加入下面的代码:

  1. <h2>Blog articles</h2>
  2.             <ul>
  3.                 <?php
  4.                     foreach ($theme->recent_posts as $post) {
  5.                         echo '<li><a href="', $post->permalink, '">',
  6.                         $post->title, '</a></li>';
  7.                     }
  8.                    
  9.                 ?>
  10.             </ul>

好了,完成了,此文资料来源Habari的官方wiki.

0 Responses to Habari中显示"最近文章" Article comments Feed

Write a response

Play nice. Be constructive. Allowed HTML tags are: <a>, <strong>, <em> and <blockquote>

« Habari中显示"… Habari中显示"… »