How to Seperate Trackbacks from Comments in WordPress?

Share:
Share

seperate_trackbacks_from_comments_wordpress_tutorial

Do you get a lot of Trackbacks and/or Comments on your Posts? Do you simply want to show Trackbacks at a different place or separately from the comments? Well, many of us want so.. Here’s a simple tutorial on How you can separate Trackbacks and Pingbacks from Comments.

Here we are going to play with the comments.php of your theme file. So make sure you back it up first.. so it may do no harm to your Blog or theme if you come across any error or do something wrong.

First things first.

Filtering out Trackbacks from Comments:

Open your comments.php in any text editor as Notepad, or WordPress’ Theme Editor will do too.

Locate for the following code:

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

Immediately after the above code, add this code:

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

Now locate this code:

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

And add this code just before the above code:

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

So, we just filtered out the Trackbacks from the comments. Now we have to create another loop to create trackbacks and pingbacks.

Creating loops for Trackbacks:

Just below this code:

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

you will find this code :

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

Just add this loop in between these two codes above:

<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() ?>
<?php } ?>
<?php endforeach; ?>
</ol>

You can play around, placing and styling as you want and your theme permits. Like changing the h3 heading to whatever suits you.

Hope this tutorial was helpful to you, leave comments if you have any questions. I’ll be more than happy to answer!

Share:
Share

Tags: ,

5 Responses to “How to Seperate Trackbacks from Comments in WordPress?”

  1. Simon | Teenius 06. Dec, 2009 at 9:00 am #

    I wanted to try this on my blog but I couldn’t find the first line in my comments.php :| :(
    Simon | Teenius´s last blog ..Ways To Find Topics For The Next Post My ComLuv Profile

    [Reply]

    Enk. Reply:

    That’s sad Simon.
    If you have basic knowledge of HTML and/or PHP you should be able to figure out the loop of comments used in your theme and follow the tutorial.
    Or feel free to share the comments.php, I’ll be more than happy to help! :)

    [Reply]

    Simon | Teenius Reply:

    Awesome, I’ll chat to you about it on MSN :)
    Simon | Teenius´s last blog ..A Brief Guide To Twitter Lists My ComLuv Profile

    [Reply]

    Enk. Reply:

    Yea sure ! :)

Trackbacks/Pingbacks

  1. uberVU - social comments - 04. Dec, 2009

    Social comments and analytics for this post…

    This post was mentioned on Twitter by enked: How to Seperate Trackbacks from Comments in WordPress http://bit.ly/8wMAKX #Wordpress…

Leave a Reply

CommentLuv Enabled