Friday, September 03, 2004

For Blogger users only: changing your "0 Comments" text

[This post will only be of interest to Blogger users. It is the second in a series of 'Blogger tools' posts; the first was on creating boxed text.]

There's something just a bit painful about turning on Comments on your blog, only to find that Blogger's now shouting Comments (0) at the bottom of all of your carefully composed posts. They might as well just change the text to say "Nobody's reading your blog,so go out and get a life"...

Hence the need for a less self-denigrating way to indicate to the reader(s) that there is/is not reader-supplied commentary available for a particular post.

The following script will make the text say "Comment", "Comment (1)", or "Comments(574)", respectively, if the post has 0, 1 or 574 comments. To use it:


  1. Edit your Settings to turn on comments, if they're not already turned on.
  2. Save your existing template (Copy, Paste, Save As to a textfile somewhere...) in case something goes horribly wrong (yet subtly enough wrong that you went ahead and Saved the "bad" changes I'm about to suggest).
  3. Edit your template:

    1. After the </title> tag (near the top), insert the following lines (Copy them from this webpage and Paste them into your template):
      <script language=javascript>
      <!--
      function myCommentDetailStr(id){
          if (id != '0'){
              if (id == '1'){
                  document.write(" (" + id + ")" );
              } else {
                  document.write("s (" + id + ")" );
              }
          }
      }
      -->
      </script>

    2. Find the "<BlogItemCommentsEnabled>" tag and the corresponding "</BlogItemCommentsEnabled>" tag; replace the text between (but not incuding) these tags with:

      <a class="comment-link" href="<$BlogItemPermalinkURL$>#comments">
      Comment<script>myCommentDetailStr('<$BlogItemCommentCount$>');</script>
      </a>

    3. Preview your weblog to make sure that it looks ok;
    4. If so, Save your template changes
    5. Make a test post, publish it, add some commentary to it to test the script
      (no, your correspondent has not done this thoroughly)




Caveats:
As I said, it hasn't been really tested yet. Apparently one needs to "register" in order to comment; will modify this post when testing has been done.

Also, in the highly unlikely event that someone did comment on this blog back when it had Haloscan-hosted commenting and was not being updated...sorry. I didn't see your comment. It's gone.






1 comment:

Anonymous said...

test, test, test, test, test...