PureNews

PureNews is an amazingly sleek and powerful news theme with unlimited color variations.

View full feature list Check out the live demo Buy this theme today

Linking to individual comments in WordPress

One important link in the comments section of wordpress is the individual comment link. If a post only has a few comments it isn’t really essential however the more comments your posts get the more helpful. The comment link allows you to link to a specific comment on a thread. This can be incredibly helpful if you are referring to the 150th comment of a post!

I thought it would be useful to explain how to add this link as there are a lot of free themes available which do not have this link in the comments template.

Here is a pic showing where i display the link on Blogging Tips :

Comment Number

As you can see, i number all comments so that its easy for people to refer to specific comments. You don’t have to do this – you could always just put ‘Link to this coment’ or something to that effect in the comment info area (eg. where the time of the comment etc is stated)

The Code

To link to a comment you use :

<a href="#comment-<?php comment_ID() ?>">

So if you wanted to link to the comment in your comment info area you could use

<a href="#comment-<?php comment_ID() ?>">Comment Link</a>

I think that numbering comments is useful though so this is the code i use :

<span class="count">
<a href="#comment-<?php comment_ID() ?>"><?php echo $i; ?></a>
</span>

<?php echo $i; ?> is the code which displays what comment number the comment is (eg the 4th comment to be posted in the article).

The css class i use is labelled count – all it does is align the link to the right hand side of the comment and make the text size a bit bigger. Here is the code to do just that :

.count {
float:right;
font-size:26px;
}

Overview

Your wordpress theme may already have this code in it however if it doesn’t and your getting a lot of comments to your posts you may find adding the link code makes it easier for your readers to refer to individual comments.

If your unsure about any aspect of it please let me know :)

Kevin Muldoon is a webmaster and blogger who lives in Central Scotland. His current project is WordPress Mods; a blog which focuses on WordPress Themes, Plugins, Tutorials, News and Modifications and useful resources such as 101 Places To Find Images For Your Blog Posts.

6 comments - Leave a reply
  • Posted by Community Building B on 17th May 2007

    Do you think that if people start referring to others by numbers as opposed to names, this would reduce the community feel of your blog?

    I would rather be called Martin than #7!

    - Martin Reed

  • Posted by Thomas Clausen on 11th Aug 2007

    I simply can't figure out where to put the code! I use k2, and I'm thinking comments.php but also where in the comments file?

    I've tried different places, and nothing is showing up

  • Posted by Kevin on 12th Aug 2007

    Could you post the code for the comments.php file in the <a>forums. Ill see if I can help :)

  • Posted by den on 17th Apr 2008

    Could you post the code for the comments.php ??