Monday

Adding recent comments to the sidebar

One of the ways to encourage visitors to stick around on your site for a little longer is to give them an idea of the comments others have recently left. This is commonly done in the sidebar, and here's how to do it in Blogger.

In your sidebar (wherever you want the comments to appear), copy and paste the following code.


<mainpage>
<h2 class="sidebar-title">Recent Comments</h2>
<ul>
<blogger>
<blogitemcommentsenabled>
<blogitemcomments>

<li><$BlogCommentAuthor$> //
<a href="http://www.blogger.com/post-edit.g?blogID=22689915&postID=114046704988137018">">
<$BlogCommentDateTime$></a></li>

</blogitemcomments>
</blogitemcommentsenabled>
</blogger>
</ul>
</mainpage>


A brief look at what this code does.

<mainpage>

This means that the following code (until the
</mainpage>
) will only appear on the front page of your site. The archive pages (with a separate post on each page) will already be displaying the comments by default, so there isn't much sense in duplicating this.

<blogger>


This will loop through each post on the page.

<blogitemcommentsenabled>


This tag checks to see that comments have been enabled for each post.

<blogitemcomments>


Loops through each comment for the post.

NB : This isn't strictly a list of recent comments, but it will certainly give you a good idea. It is, in fact, a list of comments for the posts on that page. There are other techniques for generating a true weblog-wide comment listing, but they each have their own drawbacks and will be covered in a separate post.