Note: For WordPress 2.7 and newer WordPress installations, you’ll instead want to use this tutorial.
With all the WordPress themes available to WordPress users, it always surprises me how these incredible theme authors don’t take a few extra seconds to separate their theme’s trackbacks from the comments. It doesn’t look very professional and it can make it extremely difficult to follow a conversation in the comments.
Separating your trackbacks and comments requires a minimal amount of coding work to set up. First, you’ll want to make a backup of your comments.php file just in case something goes wrong. Next, follow these three steps:
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 will filter out all of the trackbacks and pingbacks from your main comments loop. Now we need to create a second comments loop to display the 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:
<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>
You can adjust this code to display how you want to, including using a different header if you have a specific look for your header 3.
















Great article man. I found it after my friend Kyle from Kyle’s Cove included a reference to it in his article. Nice work man!
i like the article, but do you know how i can list the number of trackbacks….
Yours above says 3 Responses…
Could it say 3 Trackbacks too?
Adam – Glad you found the post useful!
With my current setup, the comments loop starts after it grabs the number of comments from the database, causing it to group the comments and trackbacks into a single total.
Unfortunately, WordPress handles trackbacks/pingbacks and comments in the same way (which is why you have to approve trackbacks like you would a comment). Therefore, it would be extremely difficult to code your comments.php file to pull them separately.
Oh good I’ve been trying to figure out how to do this. Thanks!
Jenny – Glad you found it useful!
Adam,
to count comments and trackbacks separately you should try as follow: immediately after line
put that code:
and then simply show right number as number of comments or trackbacks.
ups, it seems that code I wrote isn’t displayed, than again:
<?php
$numTrackBacks = 0;
$numComments = 0;
foreach ($comments as $comment) {
if (get_comment_type() != “comment”) { $numTrackBacks++; }
else { $numComments++; }
}
?>
Not quite the same thing, but I have two RSS filters for separating my comments and trackbacks in my RSS feeds in NetVibes — so I can always see the last 5 commenters.
http://internetducttape.com/2007/09/25/blog-maintenance-tip-netvibes-start-page/
Heck of a post.
This is great stuff. This is by far the esiest to understand WordPress Theme adjusting I have done since I switched to WordPress a few months ago. I’m going through the other articles looking for other golden nuggets of knowledge I can use on my site.
Blogger PL – Thanks for contributing the extra code!
Engtech – That is definitely useful. Thanks for providing the link.
Michael – Thanks! Hope you check back for future updates.
Bradly – Glad you found it useful! I try to discuss various news, tips, tricks, hacks, and WordPress plugins/theme reviews, so if you find that stuff useful feel free to subscribe to my feed!
That’s a great workaround and something I’ve just implemented on my site. Thanks for putting it out there.
Hey! It works! This mix up of trackbacks and comments was really pissing me off, but this is a great Tutorial, they each have their own territory now!
Cheers! Great job!
Duh! First of all, thanks for pointing out that this is a themes issue.
Thanks for this one. The Comments/Trackback issue was really bugging me.
I wanted to separate them but thought it might be too complicated. Thanks for the tip.
Thanks for all those explanations: I just did it and it’s quite nice to have trackbacks and comments separated now, I really like it! Thanks!
Awesome post! Very helpful and looks terrific when implemented. It was easy to put on this blog, I’ll be putting it in place on my others as well. Thanks! Great work!
Beautiful! This worked exactly as I wanted it to, even taking out the trackback text, and it did it in about five minutes.
Thanks so much (you saved my hide).
Thanks for sharing this. Will check it out.
http://www.nela.in/
Is there a way to set it up so it says a line of text if there isn’t any trackbacks. In a similar way to comments. Otherwise a very good tip. Thanks
is it correct?
foreach ($comments as $comment) {
if (get_comment_type() != “comment”) { $numTrackBacks++; }
else { $numComments++; }
}
Definitely a great help! Simple and clean, thanks.
This is a really great post. Thank you.
How do you separate Recent Comments from Recent Trackbacks in your sidebar?
My Recent Comments is now a widget that came with the (Revolution) theme, but it shows the comments and trackbacks all mixed together.
And even more annoying, it shows trackbacks from internal links between my own articles. Does the code above prevent that? or do you have to somehow exclude it from showing trackbacks where you yourself are the author, or from your own URL, or something like that?
I’m going to look through your other posts for other good things.
Thanks again.
@ Christine – If you are already using the Revolution theme, it should be really easy! You use the Recent Comments plugin provided.
With that plugin you can sensor out internal pings and set up trackbacks to be separate. You should see a trackback tab.
I’ll put this on my list of posts to tackle in the near future, so subscribe or check back regularly!
Thanks, Kyle.
I have a Recent Comments widget, but I can’t get in to change anything about it.
There is no Recent Comments plugin. That one you mentioned sounds excellent. I’ll go look for it, instead of the widget.
If you know of a good one, could you post a link?
Thanks again.
I think I found it. It’s called Get Recent Comments, right?
I wonder if it was there at the start and I somehow lost in during the 2.5 upgrade.
On the plugin in page, here
http://blog.jodies.de/archiv/2004/11/13/recent-comments/
it says “Widget support (but not required)”. What does that mean?
@ Christine – Yes, that is the correct plugin.
I don’t use widgets, so I think they are just saying widget use isn’t required.
I will try to get up a plugin review within the next week for this plugin. Hopefully that will give you the information you need.
Hey, thanks for this little hack! Works a treat and has really cleaned up my comments!!
hello there.
I have done things like this mods, but I would want my trackbacks/pingbacks to look more like they look in my comment section of the admin panel, with all that text around the link to my site, not just the link from where they resulted… but when I tried to use $comment->comment_text it gave me noting back
oh and by the way there is a plugin to do this separation: http://www.binarymoon.co.uk/projects/bm-track-ping/
Thanks for the info. I just put it on my blog and love it. I stumbled it and you can count on a trackback!
What do you think about creating the list, however, below the Submit comment box though?
@ John – That is up to you. I display them just below the comments because it serves as a reminder to readers that they can write about the post on their site and get a link displayed there. I also know they can sometimes generate traffic for people, so I like having them in blue.
How do I remove the Trackback when there are no trackbacks? And dispaly when there are.
Great hack, congratulations!!!
Btw, is there any code that makes possible to not count the trackbacks/pingbacks in the number of comments?
For example, in a post I have 5 comments.
1 for a user and 4 trackbacks.
I only want to show 1 instead of 5.
Is possible? how?
P.S. I dont know if the “blogger pl dot com” code is correct for me, but I dont know where to put him…
blogger pl dot com, where is to put that code?
I can’t do this. Always fail
My comments.php http://josevitor.pastebin.org/51897
I’m using WordPress Thread Comment plugin.
Amazing! greatly appreciated!
Thank you.
Can I move the code to display trackbacks before the comments? If so, where would I put it?
Thank you. I could figure out how to not show trackbacks along with comments. Was stuck over how to show them in the end. This makes things quite speedy.
I did this modification and now comments or my sidebar won’t display using internet explorer can you possibly help me?
I’m off back to work for the afternoon but if you add me (msn) to the e-mail I’m replying with maybe around 5 this evening you can help me get it right?
open my url here and use Internet explorer and you will see
works fine when using firefox!
p.s. I have subscribed!
Sorry this works perfect!
Thanks it was a bad post that messed up the page!
Just a note that under 2.7 all of this has changed with the new wp_list_comments
Working excellent.
Thanks a lot.
Cool Thanks for the tips..Worked for me
Thanks!
Thank you for this article. It’s exactly what I’ve searched for!
Greets
Andreas
This is working excellent.
Thanks a lot.
it’s adorable …
really thank you so much
Greeting from Egypt
Works great, thanks.
IMHO a nice thing could be deleting the pingbacks from comments count.
So if there are 4 comments and 3 pings, the post shows: 4 comments, and not 7 comments.
Thanks for the information, now my blog looks better…
I tried using this with my new theme from elegant theme but no luck yet with the suggested “finds”
I’ve been waiting weeks for a reply in and attempt inside their forums for the cherrytruffle theme.
I simply loved this hack it’s by far something that should be added in all wp themes!
nice tip thanks for the tut..
nice tutorial thanks for sharing.
This is great stuff. This is by far the esiest to understand WordPress Theme adjusting I have done since I switched to WordPress a few months ago. I’m going through the other articles looking for other golden nuggets of knowledge I can use on my site.
Beautiful! This worked exactly as I wanted it to, even taking out the trackback text, and it did it in about five minutes.
Thanks so much (you saved my hide).
This does not work for me. With a pingback all the comments are gone and no way to fill it in. I don’t have any knowledge and I can’t solve this problem… Have to look further for another solution.
Oh good I’ve been trying to figure out how to do this for a customer and it helped me, so thanks for sharing the “tip”
Thanks for this wonderful code! My theme was showing track backs in between comments which does not look good. Now its wonderful!
Thanks once again!
Works a treat and has really cleaned up my comments!!