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 and you followed this tutorial right 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

7 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

Leave a Reply

Feel free to leave your comment however comments are moderated before appearing on site

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