Habari虽然有recentcomments和freshcomments这两个显示最近的评论的插件,但我试了下,运气差了些,没一个能用起来,所以只能自己动手了,看到miklb和我用一样的模板,他右边sidebar的Recent Comments做的真不错,和主题风格符合的好,就看着他网站的样子做了个.
在Habari的wiki上可以查到显示最近评论的方法,这儿先简单引用下:
1)在模板theme.php文件的add_template_vars这个函数中插入如下代码,修改"25"为你想显示的数目:
- $this->assign('recent_comments',
- Comments::get( array('limit'=>25, 'status'=>Comment::STATUS_APPROVED,
- 'type'=>Comment::COMMENT, 'orderby'=>'date DESC' ) ) );
2)在需要显示的地方(比如侧边栏sidebar.php)插入:
- <h3>Recent Comments</h3>
- <ul>
- <?php foreach($recent_comments as $comment): ?>
- <li>
- <a href="<?php echo $comment->url ?>">
- <?php echo $comment->name; ?>
- </a> on
- <a href="<?php echo $comment->post->permalink; ?>">
- <?php echo $comment->post->title; ?>
- </a>
- </li>
- <?php endforeach; ?>
- </ul>
这样就能实现最近评论功能了.
接着我写下现在使用的这个模板的"最近评论"代码,稍微美化了下,引入了Gravatar头像和RSS链接.
theme.php插入相同的代码,接着在CSS中加两段:
- div#recentcomments ul{
- text-align:justify;
- padding-bottom: 7px;
- margin-bottom:7px;
- border-bottom: #eaeaea 1px solid;
- min-height: 25px;
- }
- div#recentcomments div.gravatar_mini
- {
- float:left;
- margin-right:5px;
- }
接着在sidebar.php中加入这么一段:
- <div id="recentcomments">
- <h3><a href="http://zhais.com/atom/comments" title="Comments Feed"><img alt="comments Feed"
- src="<?php echo $this->theme_url; ?>/images/feed.png" /></a> Recent Comments</h3>
- <?php foreach($recent_comments as $comment): ?>
-
- <ul>
- <div class="gravatar_mini">
- <img alt="Gravatars Icon" src = "<?php echo
- "http://www.gravatar.com/avatar/".md5( $comment->email )."?s=25" ?>">
- </div>
- <div>
- <a href="<?php echo $comment->url ?>">
- <?php echo $comment->name; ?></a>
- <?php echo " commented, "".$comment->content."""." on the post "?>
- <a href="<?php echo $comment->post->permalink; ?>">
- <?php echo $comment->post->title."."; ?></a>
- </div>
- </ul>
- <?php endforeach; ?>
- </div>
完成了 :)

Related Posts
Tag Cloud
Write a response