Tutorial : How to separate Comments and Trackbacks

I’ve always felt that showing your comments and Trackbacks separated adds a bit of professionalism to your blog. It’s hard as it is to follow a long conversation, but also having to weed out the Trackbacks makes it even more difficult. I could never really understand why people don’t do this because honestly having those two separated takes only a minimal amount of coding effort and only 2 or 3 minutes of your time but has a great impact on your readers.
To get started, make sure you back-up your comments.php file before starting to edit anything.


1 ) Access your comments.php file and locate the following code:

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

Immediately after the above code, you’ll want to place this code:

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

2) Next, you’ll want to scroll down a little bit and locate the following code:

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

Immediately before the above code, you’ll want to place this code:

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

This bit of code is used to filter out all of the tracbacks and the pingbacks from your main comments loop, meaning that we’re going to need a second loop that will display our trackbacks and pingbacks.

3 ) Almost immediately below the code from step 2 you should find this code:

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

Immediately before the above code, you’ll want to place this code:

Trackbacks
<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>

This is the code using an ordered list ( ol ) to display the latest trackbacks and pingbacks - you can style it accordingly to match your theme’s design.

If it's your first time here, you might want to subscribe to my RSS feeds or join my email subscription list ( just enter your email address in the form on the right side and click submit ).

Add to Bloglines Add to Google Add to Netvibes Add to Newsburst Add to Newsgator Add to My Yahoo

Enter your email address: