Number Of Comments Modification

Overview

This page lists a number of modifications of the comment-link that is part of the post includable.
It is strongly advised to read the documentation of this includable before you start to modify it. Also, backup your template before applying modifications or hacks.

Work around the 1 comments bug

Maybe you noticed that when you have 1 comment on a post, Blogger will tell you that you have 1 comments. This is rather strange, because the Blogger source code in the template clearly makes a difference between singular and plural. Apparently, both singular and plural are programmed the same value. This hack will work around this problem.

Open your template in HTML-edit mode, and search for the post includable. Scroll to Post Footer Line 1, and find the following piece of code:

<span class='post-comment-link'>
   <b:if cond='data:blog.pageType != "item"'>  <!-- if the page is NOT an itempage, display the link -->
      <b:if cond='data:post.allowComments'>   <!-- if the post allows comment to be made, display the link -->
         <a class='comment-link' expr:href='data:post.addCommentUrl' expr:onclick='data:post.addCommentOnclick'>
            <b:if cond='data:post.numComments == 1'>1 <data:top.commentLabel/>
            <b:else/><data:post.numComments/> <data:top.commentLabelPlural/>
            </b:if>
         </a>
      </b:if>
   </b:if>
</span>

In this code, replace <data:top.commentLabel/> with comment, and replace <data:top.commentLabelPlural/> with comments.
The new code is:
<span class='post-comment-link'>
   <b:if cond='data:blog.pageType != "item"'>  <!-- if the page is NOT an itempage, display the link -->
      <b:if cond='data:post.allowComments'>   <!-- if the post allows comment to be made, display the link -->
         <a class='comment-link' expr:href='data:post.addCommentUrl' expr:onclick='data:post.addCommentOnclick'>
            <b:if cond='data:post.numComments == 1'>1 comment
            <b:else/><data:post.numComments/> comments
            </b:if>
         </a>
      </b:if>
   </b:if>
</span>

Adding a tooltip to the comments-link

This hack adds a tooltip to the comments-link. A tooltip is a piece of text that pops up if the mouse hovers over the link.

Open your template in HTML-edit mode, and search for the post includable. Scroll to Post Footer Line 1, and find the following piece of code:

<span class='post-comment-link'>
   <b:if cond='data:blog.pageType != "item"'>  <!-- if the page is NOT an itempage, display the link -->
      <b:if cond='data:post.allowComments'>   <!-- if the post allows comment to be made, display the link -->
         <a class='comment-link' expr:href='data:post.addCommentUrl' expr:onclick='data:post.addCommentOnclick'>
            <b:if cond='data:post.numComments == 1'>1 <data:top.commentLabel/>
            <b:else/><data:post.numComments/> <data:top.commentLabelPlural/>
            </b:if>
         </a>
      </b:if>
   </b:if>
</span>

The tooltip can be added by inserting the phrase: title='your tooltip' in the anchor-element.
In the following example, the tooltip text is: 'Click here to view comments'.

<span class='post-comment-link'>
   <b:if cond='data:blog.pageType != "item"'>  <!-- if the page is NOT an itempage, display the link -->
      <b:if cond='data:post.allowComments'>   <!-- if the post allows comment to be made, display the link -->
         <a class='comment-link' expr:href='data:post.addCommentUrl' expr:onclick='data:post.addCommentOnclick' title='Click here to view comments'>
            <b:if cond='data:post.numComments == 1'>1 <data:top.commentLabel/>
            <b:else/><data:post.numComments/> <data:top.commentLabelPlural/>
            </b:if>
         </a>
      </b:if>
   </b:if>
</span>

Replacing 0 Comments

The 0 comments-phrase can be replaced by something more creative, such as 'Be the first to leave a comment!'.
In this example, we will do this replacement, and we will also implement the 1-comments workaround.

Open your template in HTML-edit mode, and search for the post includable. Scroll to Post Footer Line 1, and find the following piece of code:

<span class='post-comment-link'>
   <b:if cond='data:blog.pageType != "item"'>  <!-- if the page is NOT an itempage, display the link -->
      <b:if cond='data:post.allowComments'>   <!-- if the post allows comment to be made, display the link -->
         <a class='comment-link' expr:href='data:post.addCommentUrl' expr:onclick='data:post.addCommentOnclick'>
            <b:if cond='data:post.numComments == 1'>1 <data:top.commentLabel/>
            <b:else/><data:post.numComments/> <data:top.commentLabelPlural/>
            </b:if>
         </a>
      </b:if>
   </b:if>
</span>

We will insert an extra <b:if>...</b:if>-construct, to handle the situation where <data:top.numComments/> equals 0.
The new code is:

<span class='post-comment-link'>
   <b:if cond='data:blog.pageType != "item"'>  <!-- if the page is NOT an itempage, display the link -->
      <b:if cond='data:post.allowComments'>   <!-- if the post allows comment to be made, display the link -->
         <a class='comment-link' expr:href='data:post.addCommentUrl' expr:onclick='data:post.addCommentOnclick'>
            <b:if cond='data:post.numComments == 0'>Be the first to leave a comment!
            <b:else/>
               <b:if cond='data:post.numComments == 1'>1 <data:top.commentLabel/>
               <b:else/><data:post.numComments/> <data:top.commentLabelPlural/>
               </b:if>
            </b:if>
         </a>
      </b:if>
   </b:if>
</span>
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.