Add Recent Comment Widget in Blogger

Ever wanted to put a widget that shows the Recent Comments being written on your blog. My blog is to put what I learn about computers and in the process share my experience with everyone. Now continuing the purpose of this blog, I will share with you the procedure on how to add “Recent Comments” widget.

First go to layout => Edit HTML and search for

</head>
<script type='text/javascript'>
function commentDisplay(json) {
   for (var i = 0; i &lt; numcomments; i++)
   {
       var entry = json.feed.entry[i];
       var alturl;
       if (i == json.feed.entry.length) break;
       for (var k = 0; k &lt; entry.link.length; k++)
       {
           if (entry.link[k].rel == 'alternate')
           {
               alturl = entry.link[k].href; break;
           }
       }
       alturl = alturl.replace("#", "#comment-");
       if (entry.content)
       {
           comment = entry.content.$t;
       }
       else if (entry.summary)
           {
               comment = entry.summary.$t;
           }
           var re = /&lt;\S[^&gt;]*&gt;/g;
           comment = comment.replace(re, "");
           document.write('&lt;a href="' + alturl + '"&gt;' + entry.author[0].name.$t + '&lt;/a&gt; commented:&lt;br/&gt;');
           if (comment.length &lt; numchars) document.write(comment + '&lt;br/&gt;&lt;br/&gt;');
           else document.write(comment.substring(0, numchars) + '...&lt;br/&gt;&lt;br/&gt;');
       }
       }
</script>

Now go to Layout => Page Elements and in sidebar click add a gadget and choose HTML/JavaScript and in Configure HTML/JavaScript paste the following code

<br/><script language="javascript">
var numcomments = 5;
var numchars = 50;
</script>
<script src="http://yourblog.blogspot.com/feeds/comments/default?
alt=json-in-script&callback=commentDisplay"></script>

Change yourblog.blogspot.com to the address of your blog

Save the page and then view your blog. You can tweak the number of comments and number of characters in each comment as shown below.

recentcomment

Comments

  1. Thank you. I added this to two blogs. I had something similar before on one of the blogs, and inadvertently messed it up. I needed something to replace it, right away. This worked perfectly.

    ReplyDelete
  2. Dear, I've tried this, A widget accoured also on my blog name, सर - आँखों पर but stil the recent comments r not showing. Can u pls tell me what i've done wrong ?

    Jaikaran Singh Bhadauriya
    jai1991jai@gmail.com

    ReplyDelete

Post a Comment

Comment for encouragement

Popular posts from this blog

Configure D-Link 2750U Wi-Fi Router for Airtel

Aspire theme Problems

How to write in Hindi on Facebook