Posts RSS Comments RSS 60 Posts and 137 Comments till now

Wordpress: Seperate Pingbacks & Trackbacks From Comments

Who knows why they decided to have pingbacks and trackbacks interspersed into comments but it looks awful and we need to fix that.

A quick search on Google nets me this:

Separating Pingbacks and Trackbacks from Comments in Wordpress

I will summarize here just incase the link goes dead in the future.

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!

If you found this page useful, consider linking to it.
Simply copy and paste the code below into your web site (Ctrl+C to copy)
It will look like this: Wordpress: Seperate Pingbacks & Trackbacks From Comments

Trackback this post | Feed on Comments to this post

Leave a Reply

Close
E-mail It