Home » How to Guide

How to Separate Trackbacks from Comments in Wordpress

Published by Amit Bhawani on May 10, 2008 – 2:59 pmNo Comment

Its very much important to separate the backlinks you get to your blog posts from the general comments because, generally wordpress shows both of these in a single column sorted by time and if your posts get good number of backlinks generally from different blogs then its time you need to implement this tweak.

Advantages of Separation : If you check out this my post on Alexa Rankings i had a total of 43 comments out of which 16 were trackbacks ie 16 blogs linked to that certain post and wordpress was showing all of these in a single order confusing the general commentors because they would get confused with the trackback text. The better option would be to separate these and show real comments just below the posts and a complete list of trackbacks just below these general comments and above the comment form.

How to perform this tweak?
Go to Theme Editor & open your comments.php file and search for this code :
<?php foreach ($comments as $comment) : ?>
Once you find the above code, add these 2 lines below it
<?php $comment_type = get_comment_type(); ?>
<?php if($comment_type == 'comment') { ?>

Next search for the following code
<?php endforeach; /* end for each comment */ ?>
Once you find it, add the following code before it
<?php } else { $trackback = true; } /* End of is_comment statement */ ?>
Search for the following code in order to show trackbacks in a separate set
<?php else : // this is displayed if there are no comments so far ?>
Once you find the above code, add the following lines above it
<?php if ($trackback == true) { ?>
<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>
<?php } ?>

Thanks to problogdesign for this code, i have implemented these codes in this blog, and its showing trackbacks neatly in different set.

We will send you some more information related to How to Separate Trackbacks from Comments in Wordpress. Enter your email address : Bookmark and Share

Leave a comment!

Be nice. Keep it clean. Stay on topic. No spam.