Separating Pingbacks and Trackbacks from Comments in Wordpress
This isn’t something blogs do all that often, but ever since I saw how JohnTP separates his pingbacks and trackbacks from his regular comments I’ve wanted to take the time to figure out just how to do that myself.
From the user’s perspective, separating pingbacks and trackbacks provides a nice, clean look that doesn’t break up the flow of reader comments. As such, I hope every blog seriously considers separating pingbacks and trackbacks from regular comments. If you’re still having doubts I’d like to make the choice easier for you: the steps below show you how to separate comments from pingbacks and trackbacks.
First, you will need to modify the comments loop in your template’s comments.php file and add the following code:
<?php $comment_type = get_comment_type(); ?>This will make the $comment_type variable available so that you can place an if () statement to determine if the comment is a comment, pingback, or trackback.
Next, you’ll need to add an if () statement inside of your comments loop so that only normal comments are shown. To do this you’ll need to wrap all of the code inside of the comments loop between:
<?php if ($comment_type == 'comment') { ?>and
<?php } ?>Now that you’re only showing normal comments, you’ll need to make a copy of your comments loop so that you now have two comment loops, one right after the other. The only change you’ll need to make in the second loop is to change:
<?php if ($comment_type == 'comment') { ?>to
<?php if ($comment_type != 'comment') { ?>Now all you have to do is style the second loop to your liking. For my template I stripped out the excerpt text and added the following code to print out an appropriate indicator for pingbacks and trackbacks:
<?php
if ($comment_type == 'pingback') {
echo "Pingback";
} else if ($comment_type == 'trackback') {
echo "Trackback";
}
?>
Now that you know how to separate your regular comments from pingbacks and trackbacks what are you waiting on? Go separate them already!
Tags: wordpress, separate, comments, pingbacks, trackbacks, comments.php



