Wordpress Separate Trackbacks / Pingbacks from Comments

By gilbitron in PHP on 25/02/2009 at 05:41

Views: 1583
Tagged: wordpress

Starter:

This is a neat little Wordpress trick to separate real comments from trackbacks and pingbacks.

Main Course:

<?php if ( $comments ) : ?>
<?php foreach ($comments as $comment) : ?>
<?php $comment_type = get_comment_type(); ?>
<?php if($comment_type == 'comment') { ?>
 
<!-- It's a comment -->
<!-- Comment content goes here -->
 
<?php } else { $trackback = true; }?> 
<?php endforeach; ?>
<?php if ($trackback == true) { ?>
 
<!-- It's a trackback -->
  <ol id="trackbacks-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 } ?>
<?php else : ?>
<?php endif; ?>

Expand Report Code | Install Coda Clip

Please log in to vote.

Compliments to the Chef

No comments yet...

How was your Meal?


  • Allowed HTML: <b><strong><u><i><em><a>

  • Why ask? It helps us stop spam comments.