Monday, January 04, 2010

How to put Recent Comment widget in your blog?

I had tried so many ways to put this widget on, but it was not working and I almost give up.

Luckily, I found this script that make it works.

Follow this instruction:

1. Go to your Dashboard.

2. Choose Page Elements

3. Click Add a Gadget

4. Choose HTML/Javascript

5. Copy and paste this code:

<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://xyz.blogspot.com/feeds/comments/default?alt=json-in-script&callback=showrecentcomments">

</script><a href="http://reviewofweb.com/blogging/recent-comments-blogspot-widget/">Widget </a>by <a href="http://reviewofweb.com/">ReviewOfWeb</a>

Good luck! :)

(Credit to: ROW)

15 comments:

  1. thanks for sharing this!!

    and HAPPY MONDAY to you!

    ReplyDelete
  2. hope it's useful :)

    happy monday to you.

    ReplyDelete
  3. view my version too ^^ (not mine actually but my tutorial post)

    http://www.jejaktrend.com/2009/11/recent-comment-20.html

    ReplyDelete
  4. eh eh.. en3 jenis "How To" plak.. hehe

    ReplyDelete
  5. eldy - yours is good, too. editable :)

    ReplyDelete
  6. tupai - haha. entah kenapa boleh jadi macam tu. how's life?

    ReplyDelete
  7. What widget you are trying to add again? I thought it was comment but it must be somethingelse.

    Thank you for the tip, indeed there is so much to learn in this blogoland :)

    ReplyDelete
  8. Thanks for sharing although I won't putting it up anytime soon : )

    ReplyDelete
  9. I'm using intense debate's recent comment's plugin so no problemo lor.

    ReplyDelete
  10. ocean girl - it's a Recent Comment widget :) you should try it. cool.

    ReplyDelete
  11. foong - too messy eh? :)

    ReplyDelete
  12. tekkaus - i realize that i'll have problem to comment in your blog when my internet connection is slow. why eh?

    ReplyDelete
  13. Anonymous10:16 PM

    Моя история из жизни: мы как-то с мамой ехали в маршрутке,( мама спец по всем видам мяса на глаз определяет что это), на остановке залазит подвипывший мужик с куском свежака в одноразовом пакете. Едем. Маршрутка резко тормозит,мужик по инерции бежит вперед и пакет рвется ,оттуда выпадет свежак ,дальше мамины слова- " Мужчина,у вас вымя выпало!" я медленно сползаю под сиденье , пассажиры ржут, мужик красный - выбегает на следующей остановке :)))

    ReplyDelete
  14. Hi Faisal,

    We see that you have used our Recent Posts widget code but removed our credit code at the bottom . As per our terms (http://reviewofweb.com/blogging/recent-posts-blogspot-widget/)it is not allowed to remove the credits.

    Please put the entire code as it is in your blog post (with credits).

    Thanks!

    ReplyDelete
  15. row - edited as you wish. if you realize, i've put the credit below the post.

    thank you.

    ReplyDelete

Tamparuli Bridge (Tuaran, Sabah)

Tamparuli is a small town and a sub-district of Tuaran on the west coast of Sabah, Malaysia. It is populated mainly by native Dusuns, while ...