<script src="http://www.lawnydesigns.com/feeds/posts/default?alt=json-in-script&callback=numposts"></script>
<script src="http://www.lawnydesigns.com/feeds/comments/default?alt=json-in-script&callback=numcomments"></script>
in the code above we have asked blogger to return our JSON feed to two javascript functions named
numcomments
and numposts
so now we will create those two functions to print out the total post and comments count<script style="text/javascript">function numposts(json) { document.write('This blog has ' + json.feed.openSearch$totalResults.$t + ' posts'); }function numcomments(json) { document.write(' and ' + json.feed.openSearch$totalResults.$t + ' Comments'); }</script>
now if you paste the two sets of code together into an html/javascript widget in the following order
<script style="text/javascript">
function numposts(json) {
document.write('This blog has ' + json.feed.openSearch$totalResults.$t + ' posts');
}
function numcomments(json) {
document.write(' and ' + json.feed.openSearch$totalResults.$t + ' Comments');
}
</script><script src="http://www.lawnydesigns.com/feeds/posts/default?alt=json-in-script&callback=numposts"></script><script src="http://www.lawnydesigns.com/feeds/comments/default?alt=json-in-script&callback=numcomments"></script>
and save you should see something like my result below
of course your numbers will be different so now you know how to print out the total post and comment count on your blog i hope you enjoyed this tutorial feel free to leave you comment or suggestion
15 Responses to “How to display total post and comment count on blogger”
Anonymous
March 20, 2009Thanks lawny just what i was looking for
netpicker
May 01, 2009is there a way to display the number of comments per post on the sidebar - labels widget can display the post name but not the number of comments per post.
Lawny
May 04, 2009@netpicker
it is possible but i don't have a script to display the comments in the sidebar
suhey
September 08, 2009i will try your code to my blog! thanks
Unknown
September 19, 2009I will try too.
Netpicker--
you can try below code to display each post title and its corresponding comment(s). This script to create recent post in side bar.
For the example, click here..>>
<em>
<script language="JavaScript">
imgr = new Array();
imgr[0] = "http://i43.tinypic.com/orpg0m.jpg";
imgr[1] = "http://i43.tinypic.com/orpg0m.jpg";
imgr[2] = "http://i43.tinypic.com/orpg0m.jpg";
imgr[3] = "http://i43.tinypic.com/orpg0m.jpg";
imgr[4] = "http://i43.tinypic.com/orpg0m.jpg";
showRandomImg = true;
boxwidth = 190;
cellspacing = 8;
borderColor = "#110906";
bgTD = "#000000";
thumbwidth = 30;
thumbheight = 30;
fntsize = 12;
acolor = "#999";
aBold = true;
icon = " ";
text = "comments";
showPostDate = false;
summaryPost = 200;
summaryFontsize = 10;
summaryColor = "#ccc";
icon2 = " ";
numposts = 7;
home_page = "http://amrihgunawan.blogspot.com/";
</script>
<script src="http://myblogtalk.com/bloggertemplates/js/recentposts_thumbnail.js" type="text/javascript"></script>
</em>
Harwinder Singh
November 09, 2009Thanks for the tip.
Initially it didn't work for me, but after reversing the order of the scripts, it worked. Probably, you might want to mention in your post that the order is important.
Lawny
November 10, 2009@Harwinder
not sure what you mean but it should work either way
Nega
February 20, 2010yup. reverse the order only works..
1st goes 2nd and 2nd script goes first on your html/script on blogger..
Lawny
March 05, 2010@Nega
Thanks for the heads up! it was my mistake i have updated the post
Pratik Poddar
March 10, 2010Its not showing correct number of comments in my blog. It shows 52 but actually its more than 500 :(
Can you please help. Thanx.
Blog: http://pratikpoddarcse.blogspot.com
Lawny
March 14, 2010@Pratik
Yes i also noticed mine is showing less comments than i actually have, it is nothing to do with the script that is a problem on the blogger end
Nega
March 16, 2010yup.. same problem for me too.. i think blogger problem, same problem happens on orkut.com (on counting scraps)..
Mr_Bad
May 28, 2010It works on mine. Thanks a lot for this great code..
Lisa Turner
October 01, 2011Thanks for this tip, very much appreciated.
iTechColumn
October 07, 2011I was looking for this..Thanks for the tips..I will try it out..
Leave a Reply
Comments are moderated before appearing on site, comments that contain suspicious information, self-advertising or spam-like URLs will be deleted.
Note: only a member of this blog may post a comment.