Thursday, January 20, 2005

Smart Comment Counts

Ever looked at your comment count and asked, “1 Comments? What does that mean?” Well, there just happens to be a fix for that grammatical error; with a little bit of JavaScript and DHTML (DOM), you can make dumb counts a thing of the past. In fact, you can make your comment link say anything you want it to. I’ve chosen to put “Comment on this” in place of “0 comments”, for example.

Here’s how it’s done: right after the closing </Blogger> tag, insert this code:

<style type="text/css">

<!--
.hidden {display:none;}
-->
</style>
<MainOrArchivePage>
<script type="text/javascript">
<!--
var n=document.links;
for(var i=0; i<n.length; i++)
with(n[i])
{
if(innerHTML=="0 comments")
innerHTML="Comment on this";
else if(innerHTML=="1 comments")
innerHTML="1 comment";
}
-->
</script>
</MainOrArchivePage>
<ItemPage>
<script type="text/javascript">
<!--
var h=document.getElementsByTagName("H4");
with (h[h.length-1])
{
if(innerHTML=="0 Comments:")
className="hidden";
else if(innerHTML=="1 Comments:")
innerHTML="1 Comment:";
}
-->
</script>
</ItemPage>

Then republish your blog, and watch your counts get smarter!

Note: Some templates don’t disable the comment link on the Item Page. You can do that by searching your template for <p class="post-footer"> and then looking for the <BlogItemCommentsEnabled> ... </BlogItemCommentsEnabled> tags inside that paragraph. Simply place an opening <MainOrArchivePage> tag to the left of the opening tag, and a closing </MainOrArchivePage> tag to the right of the corresponding closing tag. Now your comment link will not display on a post page.

No comments: