(+84) 463.28.7979

How To Separate Comments And Trackbacks [WordPress Tips]


trackbacks comments How to Separate Comments and Trackbacks [Wordpress Tips]

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:

  1. <?php foreach ($comments as $comment) : ?>
  1. <?php $comment_type = get_comment_type(); ?>
  2. <?php if($comment_type == ‘comment’) { ?>

Step 2

Look for:

  1. <?php endforeach; /* end for each comment */ ?>
  1. <?php } else { $trackback = true; } /* End of is_comment statement */ ?>

Step 3

Look for:

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

Paste before:

  1. <?php if ($trackback == true) { ?>
  2. <h3>Trackbacks</h3>
  3. <ol>
  4. <?php foreach ($comments as $comment) : ?>
  5. <?php $comment_type = get_comment_type(); ?>
  6. <?php if($comment_type != ‘comment’) { ?>
  7. <li><?php comment_author_link() ?></li>
  8. <?php } ?>
  9. <?php endforeach; ?>
  10. </ol>
  11. <?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.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>