Separate Comments and Trackbacks

Mar24 in Blogging by David Shaw

If you run a wordpress blog and someone links to one of your posts, you will notice that you get something called a trackback. These are often embedded into the comments section of the post, this can be a bit annoying, this tutorial will teach you how to separate the comments and the trackbacks, to make it look a lot smarter.

First off I would like to suggest that you back-up your comments.php just in case anything goes wrong.

Now you need to open your comments.php file and locate the following line of code:


<?php foreach ($comments as $comment) : ?>

Now directly below that line of code you will need to add this code:


<?php $comment_type = get_comment_type(); ?>
<?php if($comment_type == 'comment') { ?>

The above code checks the comment type to see if it is in fact a comment, or a trackback.

A little bit further down the file you will find the following line of code:


<?php endforeach; /* end for each comment */ ?>

Directly above this code you will need to add the following code:


<?php } /* End of is_comment statement */ ?>

This will close the ‘if statement’ that you opened in the previous code. You have now separated the comments and the trackbacks, you will now need to display the trackbacks.

Close to where you made the last edit you will find a line of code similar to this:


<?php else : // this is displayed if there are no comments so far ?>

Directly above it you will need to add this code:


<h3>Trackbacks</h3>
<ol>
<?php foreach ($comments as $comment) : ?>
<?php $comment_type = get_comment_type(); ?>
<?php if($comment_type != 'comment') { ?>
<li><?php comment_author_link() ?></li>
<?php } ?>
<?php endforeach; ?>
</ol>

You may find that you need to edit the above code to fit in with the style of your website.

You have now separated the comments and trackbacks on your blog, and made it look a lot more professional.

Feel free to comment on this post, or post a link to it, to see how this works, as I have this installed on my blog.


5 Responses so far | Have Your Say!

  1.   Separating Comments & Trackbacks With Threaded Comments by Online Opportunity - Gravatar

      Separating Comments & Trackbacks With Threaded Comments by Online Opportunity  |  April 19th, 2008 at 2:01 am #

    [...] for my website which informed my sites visitors how they could amend their comments.php file to separate the comments and trackbacks, thus making the comments section of your blog look alot smarter. As part of Jay’s Guest [...]

  2. Nebraska - Gravatar

    Nebraska  |  July 7th, 2008 at 9:58 pm #

    nice topic,

  3. David Shaw - Gravatar

    David Shaw  |  July 7th, 2008 at 10:04 pm #

    No Worries

  4. Missouri - Gravatar

    Missouri  |  July 8th, 2008 at 5:35 am #

    nice page,

  5. David Shaw - Gravatar

    David Shaw  |  July 8th, 2008 at 8:07 am #

    Cheers

Leave a Feedback

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  Search