How to Show Total Posts & Comments in Your Sidebar?

You can show total number of posts and comments on your blog by simply adding this small piece of code in your sidebar.

1- Log in to Blogger | Dashboard | Layout | Page Elements and on your sidebar click Add a Gadget link.

2- A new window will pop-up, scroll down and select HTML/JavaScript as your new widget.

3- In the Title field type any title and in the Content field paste the following code:

<script style="text/javascript">
function numberOfPosts(json) {
document.write('Posts: <b>' + json.feed.openSearch$totalResults.$t + '</b><br>');
}
function numberOfComments(json) {
document.write('Comments: <b>' + json.feed.openSearch$totalResults.$t + '</b><br>');
}
</script>
<font color="blue"><script src="YOUR BLOG URLfeeds/posts/default?alt=json-in-script&callback=numberOfPosts"></script>
<script src="YOUR BLOG URLfeeds/comments/default?alt=json-in-script&callback=numberOfComments"></script></font>


Note: Replace YOUR BLOG URL with full URL of your blog like http://yourname.blogspot.com/.

4- Save and see the result.

No comments:

Post a Comment