Comments Tags

There are two sections of comment tags in a template. One section simply creates the links that readers see next to your posts and click on to leave you a comment. The other section displays the comments themselves. We'll look at these two parts separately.

These examples show only a minimal amount of code to make the comments work. You are, of course, welcome to add any formatting that you like to it, so that it matches the rest of your blog.

Links:

The following piece of code will print a link reading "X comments" where "X" is the number of comments that have been left on that post so far. It should be placed between the <Blogger> and </Blogger> tags that display your posts, and it usually goes in the byline, where the author's name is listed.


<BlogItemCommentsEnabled>
   <a href="<$BlogItemCommentCreate$>" 
   <$BlogItemCommentFormOnClick$>>
   <$BlogItemCommentCount$> comments</a>
</BlogItemCommentsEnabled>

First, notice the <BlogItemCommentsEnabled> tags that surround the others. This is so the rest of the code will only be displayed on posts for which comments are enabled. The link to <$BlogItemCommentCreate$> will point to the page where you can both read existing comments and create a new one. <$BlogItemCommentFormOnClick$> includes the code that opens the link in a popup window, if you have that option selected. Note that it goes inside the opening <a> tag. Finally, <$BlogItemCommentCount$> simply prints out the number of comments for that post. You can put whatever text you like in place of "comments."

Comments:

This part of the code will also go between the <Blogger> and </Blogger> tags, but you will probably also want to enclose them in <ItemPage> and </ItemPage> tags as well, so the comments only appear on your post pages, and don't clutter up the main page of your blog.


<BlogItemCommentsEnabled>

   <a name="comments"></a>


   <h4><$BlogItemCommentCount$> Comments:</h4>

     
   <BlogItemComments>
      <a name="<$BlogCommentNumber$>"></a>

      <p class="comment-body">
         <$BlogCommentBody$>
      </p>

      <p class="comment-data">
         By <$BlogCommentAuthor$>, at
         <a href="#<$BlogCommentNumber$>">
         <$BlogCommentDateTime$></a>
         <$BlogCommentDeleteIcon$>
      </p>

   </BlogItemComments>

   <p><a href="<$BlogItemCommentCreate$>" 
   <$BlogItemCommentFormOnClick$>>
   Post a Comment</a></p>

</BlogItemCommentsEnabled>

Here we see a few tags that tie in to the previous bit of code. Once again, we've enclosed everything in <BlogItemCommentsEnabled> so posts that don't allow comments won't print anything. We also have <$BlogItemCommentCount$> as before, to display the number of comments.

The <BlogItemComments> tags mark the section of code that cycles through each comment to print it out. The <$BlogCommentBody$>, <$BlogCommentAuthor$> and <$BlogCommentDateTime$> tags all print out the information you would expect them to, with the added benefit that the author tag includes a link to the author's profile or webpage, if they have one. The <$BlogCommentNumber$> gives the ID number of each comment, for creating permalinks, just like the ID numbers of regular posts.

Finally, there are a couple little tags to round out the functionality. <$BlogCommentDeleteIcon$> inserts a delete button for each comment, but only if the person viewing it is the comment author or an administrator of the blog. No one else is allowed to delete comments. <$BlogItemCreate$> adds the link that lets people leave new comments.


Creative Commons License

The text of this Blogger Help article is licensed under a Creative Commons Attribution-ShareAlike 2.5 License. All formatting and style elements of this page are not available under this license, and Blogger retains all rights in those elements.