Setup a Blog: Fix the comment count grammar

Blogger Comments



Continued from How to add Blogger Beta Search Box


Old design, new trick



It took me all night to port my old blog design, a day after Blogger Buzz announced that it opened Edit HTML. Some of my old tweaks are incompatible, like the custom comment form, and photo favatar. If I have the time, or if inspiration strikes me, I shall look at what can be done.



Fortunately, most of my design tweaks (one column minimalist, categories, hiding the navbar/adding search box) survived the migration.



One of those which surived (albeit transformed), is the correct grammar comment count tweak.





History



The original correct grammar hack was first written last January 2005 by the anonymous author of
Blogger Templates. It was a simple workaround involving replacement of 1 comments to 1 comment.



8 months later, it was picked up by javascript expert Johan Sundström, and improved upon it using complex javascript.



Last February 2006, Gaby de Wilde, came up with a simple solution without using javascript.



A few months later, both Aditya Mukherjee, and Annie Bluesky came up with their own flavor of javascript which satisfy three conditions:



1. If comment is zero, it should display 0 comments.



2. If comment is one, it should display 1 comment.



3. If comment is more than one, it should display [how many] comments.




Finding the Blogger Beta Comment Links



In the Post Pages





In the Main, or Archive page:






The Comment Count Tags Explained



<b:if cond='data:blog.pageType != "item"'> is a conditional tag. Anything enclosed inside this tag will be displayed on the main or archive pages of your blog. In simpler terms, anything enclosed will not be shown in the post pages. It replaced the now obsolete <MainOrArchivePage> of the pre-beta blogger.



<b:if cond='data:post.allowComments'> is another conditional tag. If you allow comments, anything enclosed will be executed.



</b:if> is the closing element for conditional tags.






a is an anchor for a link. expr is a shorthand for expression. href is the target pointer. data: is the standard blogger beta layouts tag. post.addCommentUrl is the url if you're adding comment in your post. onclick is an expression that will execute when you click the link. post.addCommentOnclick will add comment on your post if you click on the link.



<data:post.numComments/> is a post comment tag. The number of comment(s).



<b:if cond='data:post.numComments == 1'> is another conditional tag. This tag states that If the number of comment in the post is equal to 1.



<data:top.commentLabelPlural/> is a post label tag, particularly a plural comment label. This reads in browsers as Comments.




The Experiment



The easiest port which comes to my mind when I found out the new if/else conditional tag of Blogger Beta, is the correct comment count.


The basic conditional code is already laid out by the Blogger Development Team. It's just a matter of making sure the three conditions of the former hacks of Aditya Mukherjee and Annie Bluesky is met.


Nevertheless, it still took me at least an hour of trial and error before I came up with a working code. Here are some things I learned from the process:



1. Standard programming equations like ==, !=, >, < works.


2. Conditions can still exist inside <b:else/>, for example, I've tried displaying BOTH ==1 and >1 at the same time, and it works!





3. Sandwiching using one line tag like <b:else if cond... do NOT work.



4. Nesting using different tags, however works <b:else/><b:if cond...



To Fix the Comment Count



1. If you've haven't migrated to Blogger Beta, see my instruction on how.



2. Click Edit HTML.



3. Find this code (This will occur twice on the standard Blogger templates):





4. Replace the code with this (If you're using a standard template like Minima, replace twice.)



5. Click Save Template.



To Customize



Just replace 1 comment or Reply to this Post, or comments, with your prefered words.



For example this blog uses Be the first to comment, instead of Reply to this post



Notes



That's it! Hope you implemented it well. If you have some questions or suggestions, leave a comment here, and I'll get back to you as soon as I can.



5 comments:

  1. ... (09 January, 2007 00:55)

    This worked great....I was worried when I changed over to the new Blogger that I would lose this and 4 days of leaving messages on the Help Forum did nothing for me....thanks so much.

    kiki (18 March, 2007 11:10)

    Hello there!
    Forgive me but I don't feel very comfortable with new blogger :(
    My blog started from scratch using the new blogger beta and I'd really love to use you hack...
    The main problem is that I'm not able to find the code you suggest in my page :(
    How can I solve this problem?
    Thank you for your kind attention!
    :)

    Vlada, Czech Republic (11 April, 2008 01:35)

    Hello,
    I'd like to create page element with sentence. But it should be displayed only on homepage.
    Do you think is it possible?

    Thank you
    Vlada

    liuis (23 December, 2008 19:41)

    Thank you man. Really helpfull.

    FunBlogger (04 June, 2010 19:20)

    One of the main feature of using third party comment system is Reply option to comments which blogger lack.
    I recently saw this tutorial on How to add reply option to blogger comments and thought to share with you

Post a Comment