How to Separate Comments and Trackbacks [Wordpress Tips]

Advertisement

trackbacks-comments.gif

Most wordpress themes out there (by default) combine both comments and trackbacks / pingbacks together and display under the same list. But why bother separating them? Simply to make things looks more organize so your blog commenters have a clearer picture what are the comments, what’s not. Doing it is not hard, but you need toe be using independent Wordpress blog (not the wordpress.com), provided with access to change comments.php. Prepare your favorite editor, and here we go.

You will be adding and editing you comments.php. So do a backup of that file before you start amending it.

Step 1

Look for:

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

Paste after:

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

Step 2

Look for:

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

Paste before:

<?php } else { $trackback = true; } /* End of is_comment statement */ ?>

Step 3

Look for:

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

Paste before:

<?php if ($trackback == true) { ?>
  <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>
<?php } ?>

That’s it. Update your blog and you’ll notice Trackbacks have been pulled out from comments and displayed underneath. If you want to display Trackbacks before comments. the easiest way is adding <div> to both and control the style via CSS. Have fun.

Read also: 40+ Most Wanted Wordpress Tricks and Hacks

Related Contents

Sponsors

Posted by hongkiat in Wordpress, Wordpress Tips Tricks , at 06.08.08

Tags: , , , ,

Comments

  1. Tan Kahong June 9th, 2008

    This is a very good tips indeed. Thanks for sharing.

    Reply
  2. Syahid A. June 9th, 2008

    Good wordpress tips HK. The way you arrange the comments and trackbacks is really practical.

    Reply
  3. Mat June 10th, 2008

    Nice tips..Thanks a lot HK

    Reply
  4. xiaomo June 19th, 2008

    thank you~useful

    Reply
  5. JORGE July 29th, 2008

    bueno

    Reply
  6. David Leggett August 14th, 2008

    Appreciate the help mate :)

    Reply
  7. Downloader August 14th, 2008

    Nice download. thanks

    Reply
  8. Free Adobe Photoshop Downloads August 25th, 2008

    Interesting information. Could you suggest more resources for this?

    Reply
  9. KK Stylist - Kristy Laschober August 27th, 2008

    That’s terrific, Thank You!

    Reply
  10. Play Online Games - Arcade Games Online September 2nd, 2008

    Congrats, take this opportunity to invite to visit my site: http://playonlinegames.info

    Reply
  11. Sonny September 2nd, 2008

    good.

    Reply
  12. make quick money October 14th, 2008

    There is no such thing as a moral or an immoral book. Books are well written or badly written.

    Reply
  13. Ivor October 22nd, 2008

    Thank you.
    It worked out perfectly.

    Reply
  14. p@r@noid December 27th, 2008

    Didnot worked for me probably using the third party theme or something I missed :(

    Reply
  15. hoolio February 7th, 2009

    RS7vjd hi! this is

    Reply
  16. AltevaKetquet February 11th, 2009

    Interesting and communicative, but would make something more on this topic?

    Reply
  17. Rad April 7th, 2009

    Thanks for the fix, worked a treat.

    Reply
  18. David April 18th, 2009

    thanks! it works well

    Reply
  19. Patrick Sweeney July 7th, 2009

    Is there a way to work this with WordPress 2.8 since it uses a new system of displaying the comments?

    Reply
  20. imad July 14th, 2009

    thas goode

    Reply
  21. kasumi August 24th, 2009

    Thank you soooo much! I was serching this for hours! Sry for my bad englisch!

    Reply
  22. Polokokta September 15th, 2009

    THX :)

    Reply
  23. Genry September 23rd, 2009

    Thank you soooo much!

    Reply
  24. Ezuca October 3rd, 2009

    Thank You so much. I have been looking for this.

    Reply

Leave a reply