April 4th, 2009 in Wordpress Tutorials by Richard Carpenter
Seperating Trackbacks & Pingbacks
Hello, welcome to another tutorial by hv-designs. Today we’ll be diving into wordpress again looking at seperating our comments and our trackbacks.
Most blogs i visit or have seen dont bother to seperate there comments and tracksbacks, personnally i think it looks better and more orgainised. It can be achived with minium effort and very little code. In todays tutorial il be seperating our trackbacks and comments using the “mywordpress theme” tha we previously created a couple of days ago. Open up your comments.php file in dreamweaver or notepad. The file should be located in the theme directory.

Once open locate the line “php foreach $comments as $comment”.

After this line paste this snippet of code.
<?php $comment_type = get_comment_type(); ?>
<?php if($comment_type == 'comment') { ?>
Your code should now look like this.

Scroll down and locate the end of comment loop. “php endforeach; /* end for each comment */”.

Just before the code above we need to end our “is comment statment”. Which looks like this.
<?php } /* End of is_comment statement */ ?>
The code should look like this.

What does all this code do i here you shout????? Basically the code will seperate all your trackbacks and pingbacks from the main comments loop. This will allow us to add a second comments loop to the comments file to display the trackbacks and pingbacks only.
Locate this snippet of code inside your comments.php file.
<?php else : // this is displayed if there are no comments so far ?>

Just before it add 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>

If you are using the “mywordpress theme” change the H3 tag from H3 to H1 or H2. Thats it all done, the code above can then be styled as you wish, its not that different from when we styled our comments.php file in the “my wordpress theme tutorial”. If you liked this tutorial please subscribe to our twitter and RSS feeds. Thanks for reading, till next time.
Be Part Of The Community!
Become part of the hv-designs community.
Subscribe Via RSS or Follow Us On Twitter.






13 Responses to “Seperating Trackbacks & Pingbacks”