How To Add Recent Comments Widget For Blogger Blog

Posted by Lasantha Bandara on April 23rd, 2009 File Under : comments, gadget, html, widget5 Comments

1.Log in to your dashboard--> layout- ->Page Elements

2.Click on Add a Gadget. Select HTML/Javascript.

3.Select the whole code given below and paste it in the widget box you have just opened above.

<script style="text/javascript">
function showrecentcomments(json) {
var numcomments = 5;
var showcommentdate = true;
var showposttitle = true;
var numchars = 100;
for (var i = 0; i < numcomments; i++) {
var entry = json.feed.entry[i];
var alturl;
if (i == json.feed.entry.length) break;
for (var k = 0; k < entry.link.length; k++) {
if (entry.link[k].rel == 'alternate') {
alturl = entry.link[k].href;
break;
}
}
alturl = alturl.replace("#", "#comment-");
var postlink = alturl.split("#");
postlink = postlink[0];
var linktext = postlink.split("/");
linktext = linktext[5];
linktext = linktext.split(".html");
linktext = linktext[0];
var posttitle = linktext.replace(/-/g," ");
posttitle = posttitle.link(postlink);
var commentdate = entry.published.$t;
var cdyear = commentdate.substring(0,4);
var cdmonth = commentdate.substring(5,7);
var cdday = commentdate.substring(8,10);
var monthnames = new Array();
monthnames[1] = "Jan";
monthnames[2] = "Feb";
monthnames[3] = "Mar";
monthnames[4] = "Apr";
monthnames[5] = "May";
monthnames[6] = "Jun";
monthnames[7] = "Jul";
monthnames[8] = "Aug";
monthnames[9] = "Sep";
monthnames[10] = "Oct";
monthnames[11] = "Nov";
monthnames[12] = "Dec";
if ("content" in entry) {
var comment = entry.content.$t;}
else
if ("summary" in entry) {
var comment = entry.summary.$t;}
else var comment = "";
var re = /<\S[^>]*>/g;
comment = comment.replace(re, "");
document.write('<br/>');
if (showcommentdate == true) document.write('On ' + monthnames[parseInt(cdmonth,10)] + ' ' + cdday + ' ');
document.write('<a href="' + alturl + '">' + entry.author[0].name.$t + '</a> commented');
if (showposttitle == true) document.write(' on ' + posttitle);
document.write('<br/>');
if (comment.length < numchars) {
document.write('<i>');
document.write(comment);
document.write('</i>');}
else
{
document.write('<i>');
comment = comment.substring(0, numchars);
var quoteEnd = comment.lastIndexOf(" ");
comment = comment.substring(0, quoteEnd);
document.write(comment + '...<a href="' + alturl + '">(more)</a>');
document.write('</i>');}
document.write('<br/>');
}
document.write('<br/>');
}
</script>
<script src="http://YOURBLOG.blogspot.com/feeds/comments/default?alt=json-in-script&callback=showrecentcomments">
</script>

Note : Replace "http://YOURBLOG.blogspot.com" with Your blogspot URL.

4. Now Click Save and Refresh Your site.

File Under : comments, gadget, html, widget

5 Responses to “How To Add Recent Comments Widget For Blogger Blog”

  1. 4everskyline says:

    yeah,its work! thx a lot..

  2. 4everskyline says:

    tanks for the nice widget,
    but i found that the widget fail to display chinese character on the "post title",any way to fix it?

    thanks! =]

  3. Dattatray Aware says:

    Thank YOU!

  4. mediafiremovieloverz says:

    thanks a lot.... it works 🙂

    mediafiremovieloverz.blogspot.com

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.