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.



Saturday, October 6th, 2007 at 12:11 pm
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!
Monday, October 8th, 2007 at 10:22 am
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?
Monday, October 8th, 2007 at 10:44 am
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.
Tuesday, October 16th, 2007 at 4:22 pm
Oh good I’ve been trying to figure out how to do this. Thanks!
Tuesday, October 16th, 2007 at 5:45 pm
Jenny - Glad you found it useful!
Thursday, October 18th, 2007 at 7:25 pm
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.
Thursday, October 18th, 2007 at 7:31 pm
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++; }
}
?>
Sunday, October 21st, 2007 at 10:43 am
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/
Sunday, October 21st, 2007 at 11:56 am
Heck of a post.
Thursday, October 25th, 2007 at 6:51 pm
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.
Friday, October 26th, 2007 at 1:45 pm
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!
Sunday, October 28th, 2007 at 11:09 am
That’s a great workaround and something I’ve just implemented on my site. Thanks for putting it out there.
Monday, October 29th, 2007 at 7:15 pm
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!
Thursday, November 1st, 2007 at 11:51 am
Duh! First of all, thanks for pointing out that this is a themes issue.
Friday, November 16th, 2007 at 5:47 pm
Thanks for this one. The Comments/Trackback issue was really bugging me.
Saturday, February 2nd, 2008 at 2:52 pm
I wanted to separate them but thought it might be too complicated. Thanks for the tip.
Sunday, February 3rd, 2008 at 2:55 pm
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!
Thursday, February 14th, 2008 at 3:34 pm
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!
Wednesday, March 12th, 2008 at 3:55 pm
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).
Monday, March 17th, 2008 at 11:21 am
Thanks for sharing this. Will check it out.
http://www.nela.in/
Saturday, April 12th, 2008 at 9:02 am
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
Saturday, April 19th, 2008 at 7:24 am
is it correct?
foreach ($comments as $comment) {
if (get_comment_type() != “comment”) { $numTrackBacks++; }
else { $numComments++; }
}
Saturday, April 19th, 2008 at 3:23 pm
Definitely a great help! Simple and clean, thanks.
Thursday, April 24th, 2008 at 2:58 pm
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.
Thursday, April 24th, 2008 at 5:23 pm
@ 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!
Friday, April 25th, 2008 at 4:08 am
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.
Friday, April 25th, 2008 at 4:17 am
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?
Friday, April 25th, 2008 at 9:01 am
@ 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.
Tuesday, May 13th, 2008 at 8:04 am
Hey, thanks for this little hack! Works a treat and has really cleaned up my comments!!
Friday, May 16th, 2008 at 1:57 am
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
Friday, May 16th, 2008 at 1:59 am
oh and by the way there is a plugin to do this separation: http://www.binarymoon.co.uk/projects/bm-track-ping/
Tuesday, June 3rd, 2008 at 11:41 am
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?
Tuesday, June 3rd, 2008 at 6:38 pm
@ 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.
Wednesday, June 4th, 2008 at 9:10 am
How do I remove the Trackback when there are no trackbacks? And dispaly when there are.
Thursday, June 19th, 2008 at 8:53 am
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…
Friday, June 20th, 2008 at 9:16 am
blogger pl dot com, where is to put that code?
Wednesday, July 16th, 2008 at 4:09 pm
I can’t do this. Always fail
My comments.php http://josevitor.pastebin.org/51897
I’m using Wordpress Thread Comment plugin.
Saturday, August 23rd, 2008 at 2:51 am
Amazing! greatly appreciated!
Monday, September 8th, 2008 at 1:43 pm
Thank you.
Tuesday, September 9th, 2008 at 7:14 am
Can I move the code to display trackbacks before the comments? If so, where would I put it?
Friday, October 3rd, 2008 at 11:05 pm
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.
Friday, October 24th, 2008 at 12:30 pm
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!
Sunday, October 26th, 2008 at 1:24 am
Sorry this works perfect!
Thanks it was a bad post that messed up the page!
Sunday, November 9th, 2008 at 5:09 pm
Just a note that under 2.7 all of this has changed with the new wp_list_comments
Tuesday, December 2nd, 2008 at 11:13 am
Working excellent.
Thanks a lot.
Friday, January 9th, 2009 at 7:58 pm
Cool Thanks for the tips..Worked for me
Sunday, January 25th, 2009 at 11:09 pm
Thanks!
Sunday, February 8th, 2009 at 3:17 pm
Thank you for this article. It’s exactly what I’ve searched for!
Greets
Andreas
Thursday, March 5th, 2009 at 3:46 pm
This is working excellent.
Thanks a lot.
Saturday, March 21st, 2009 at 6:43 am
it’s adorable …
really thank you so much
Greeting from Egypt
Monday, May 4th, 2009 at 9:46 am
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.
Thursday, June 25th, 2009 at 6:13 am
Thanks for the information, now my blog looks better…
Trackbacks/Pingbacks
Leave A Comment
Become one of our
Featured Sites
Recent Trackbacks
Contributing Authors
Archives
Extras
WordPress Hacks Copyright © 2007-2009 | An Apricot Media Website
Template by StudioPress | Custom Design by Kyle Eslick and Blog Design Studio
RSS Feed Email RSS