Aside

Displaying Comment Number Next to Posts

Tutorial 14 Comments »

A lot of people have commented on my new design how they love the comment bubble next to the post title.  It’s a great way to foster communication and showcase how many people are talking on your site.   So, if you want to add the same functionality to your site, here is the fastest way to do it!

image

First, you should note in your “index.php” file some code that looks something like this:

<h2 class="posttitle"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>

To break that down, this is a H2 that inserts an automatic link to the post (<?php the_permalink() ?>) and automatically grabs the title from the post (<?php the_title(); ?>).

To put this in your own blog, ou can either start with your own comment bubble design or grab this one:

[link to comment bubble]

I’ve included the PSD so you can change the color as you need to.  You can either add in a background color or save it as a PNG file with transparency – it works either way. Save and upload your comment bubble (JPG, PNG, or GIF only!) either via FTP or the Media Uploader and save the hyperlink – you’ll need it in a second. Head into your theme editor and look for the above code.  Right above it, insert this code:

<div class="commentbubble"><?php comments_number('0', '1', '%'); ?> </div>

To clarify, this adds a div container with the “commentbubble” and inserts the code to call the comments.  The ‘%’ is a variable number that calls any number that’s not 0 or 1.

Finally, add the CSS into your stylesheet:

.commentbubble {
    background-image: url(URL-GOES-HERE);
    height: 37px;
    width: 49px;
    color: REPLACE WITH COLOR;
    font-size: 30px;
    text-align: center;
    padding-top: 5px;
    margin-right: 13px;
    float:left;

}

Save the edits, and preview.  It should put the comment bubble right next to the title.  If you are having trouble having your content text or pictures wrapping around the bubble with the title, right after the commentbubble div, put this code:

<div style=”clear:both”></div>

This is a clearing div that will stop the text-wrapping.

14 Responses to “Displaying Comment Number Next to Posts”

  1. 7 Strategies for Increasing Your Blog Comments Says:

    [...] Display your comment count prominently. I can’t explain this, but I can tell you that since I started displaying the comment count next to my post titles, the number of my comments has increased dramatically. If the number is low, people want to jump in and be among the first to comment. If the comment count is high, readers think the topic is hot and want to get in on the action. Either way, you win. (I did this on my WordPress blog by modifying some code originally posted by Mitch Canter.) [...]

  2. rwscold Says:

    Good stuff here. I've never really considered this but I can see the reason. Just like digg the momentum builds as users see more diggs or ratings.

  3. Anonymous Says:

    Good stuff here. I’ve never really considered this but I can see the reason. Just like digg the momentum builds as users see more diggs or ratings.

  4. Suraj Reddy Says:

    This was very helpful, thanks for posting it – it'd be great if your links were updated though :)

    Also, if anyone's having trouble with the comments_number function, there's another one you can also use called get_comments_number – you'll have to use an echo before it.

    God bless

  5. Suraj Reddy Says:

    This was very helpful, thanks for posting it – it’d be great if your links were updated though :)

    Also, if anyone’s having trouble with the comments_number function, there’s another one you can also use called get_comments_number – you’ll have to use an echo before it.

    God bless

  6. Suraj Reddy Says:

    This was very helpful, thanks for posting it – it'd be great if your links were updated though :)

    Also, if anyone's having trouble with the comments_number function, there's another one you can also use called get_comments_number – you'll have to use an echo before it.

    God bless

  7. Kenneth Hardy Says:

    I loved your tutorial <3 Worked out great. Going to use this to many things :D

    Thanks !

  8. Kenneth Hardy Says:

    I loved your tutorial <3 Worked out great. Going to use this to many things :D

    Thanks !

  9. WritRams Says:

    This was just the tutorial I was looking for–thanks so much! Can you tell me how to get the comment bubble to link to the comments section for that post? (So people can click on the comment count bubble, go to the comments for that specifis post and then leave a reply.) Thanks.

  10. Smithem Says:

    does this work for Blogger??

  11. Smithem Says:

    does this work for Blogger??

  12. Tyler Longren Says:

    Link to the PSD seems to be gone. Any chance of getting that back?

  13. Anonymous Says:

    great post. I look forward to making my own comment box.

  14. aparchedsoul Says:

    Is the link to the comment bubble gone? I don’t see it.

Leave a Reply