How to display total post and comment count on blogger

In this tutorial i will show you how we can print out the total post and comment count of your blog using our blogs feed so first we need to add these two lines of javascript code which asks blogger to return our feed in JSON format which is a set of javascript objects. Don't forget to replace the red code with the URL of your blog

<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”

Thanks lawny just what i was looking for

netpicker

May 01, 2009

is 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.

@netpicker
it is possible but i don't have a script to display the comments in the sidebar

i will try your code to my blog! thanks

I 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>

Thanks 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.

@Harwinder
not sure what you mean but it should work either way

yup. reverse the order only works..
1st goes 2nd and 2nd script goes first on your html/script on blogger..

@Nega
Thanks for the heads up! it was my mistake i have updated the post

Its 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

@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

yup.. same problem for me too.. i think blogger problem, same problem happens on orkut.com (on counting scraps)..

It works on mine. Thanks a lot for this great code..

Thanks for this tip, very much appreciated.

I 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.

Copyright © 2019 All Rights Reserved | Privacy Policy | Disclaimer Design by LawnyDesigns | Powered by Blogger