雁起平沙的网络日志

数量金融与R

给博客侧边栏添加近期评论

| Comments

在我翻译的为Octopress修改主题和自定义样式一文后面,Eric Lau问我如何在博客侧边栏显示近期评论。本文就是针对这一问题的简短教程。

第一步:在disqus.com获取代码

登录到disqus.com,选择评论所在的网站,进入Admin,选择Tools,在code中,是Extra Widgets的代码,提供了几种Widgets插件,分别是Combination(组合式)、Recent Comments(近期评论)、 Popular Threads(热门话题)、Top Commenters(最近评论人)。该工具可以根据用户设置的参数生成代码。

第二步:把代码添加到octopress

按照为Octopress修改主题和自定义样式一文的描述,在sidebar里添加一个section,比如叫做recent_comments.html,代码如下:

recent_comments.html (../source/_includes/custom/asides/recent_comments.html)
1
2
3
4
5
6
<section id="comment_sidebar">
<h1>近期评论</h1>

<script type="text/javascript" src="http://ypchencn.disqus.com/recent_comments_widget.js?num_items=5&hide_avatars=0&avatar_size=32&excerpt_length=20"></script><a href="http://disqus.com/">Powered by Disqus</a>

</section>

第三步:修改_config.yml

按照为Octopress修改主题和自定义样式一文的描述,修改_config.yml,以决定评论插件出现的位置。

Sidebar configuration (_config.yml)
1
2
3
4
5
6
7
8
9
10
# list each of the sidebar modules you want to include, in the order you want them to appear.
# To add custom asides, create files in /source/_includes/custom/asides/ and add them to the list like 'custom/asides/custom_aside_name.html'
default_asides:     [asides/recent_posts.html, custom/asides/recent_comments.html, custom/asides/blogroll.html,custom/asides/weibo.html, custom/asides/copyleft.html,custom/asides/feed.html]

# Each layout uses the default asides, but they can have their own asides instead. Simply uncomment the lines below
# and add an array with the asides you want to use.

blog_index_asides:  [custom/asides/about.html, asides/recent_posts.html, custom/asides/recent_comments.html, custom/asides/blogroll.html, custom/asides/weibo.html, custom/asides/copyleft.html, custom/asides/feed.html]
post_asides:        [asides/recent_posts.html, custom/asides/recent_comments.html, custom/asides/blogroll.html, custom/asides/weibo.html, custom/asides/copyleft.html, custom/asides/feed.html]
# page_asides:

Comments