Sunday, November 13, 2011

Add Counter to the Comments

The default commenting system of blogger lacks numbering of comments. So, while commenting for a particular comment in the list, it is very difficult to point out. But it can be solved by adding some line of codes in the template which results counter for each comment. So, reference to a particular comment will be easier. Following are the steps involved to achieve this:
Step 1: Click Template -> Edit HTML (Click Proceed if you are using new looks of blogger). Click Expand Widget Template. Find the following code using Ctrl+F.
<dl expr:class='data:post.avatarIndentClass' id='comments-block'>
Step 2: Add the following code after the selected code:
<!-- set comment counter Start -->
<script type='text/javascript'>
  var regexpatt = new RegExp('commentPage=([0-9]*)');
  var results = regexpatt.exec( window.location.href );
  if(results == null)
    var CommentsCounter = 0;
    var CommentsCounter = (results[1] - 1) * 200;
<!-- set comment counter End -->
Step 3: Find the following code again as in Step 1:
Step 4: Add the following code after the selected code:
<!-- Comment count and display START -->
<div class='commentnumber' style='font-size: 20px;padding:0 10px;'>
<a expr:id='&quot;comment-&quot; +' expr:href='&quot;#comment-&quot; +' title='Comment permalink' style='float:right; margin-top:-20px;'>
<script type='text/javascript'>
CommentsCounter=CommentsCounter+1; document.write(CommentsCounter)
<!-- Comment count and display END -->
Step 5: Save the template. You are done.