Home / comment / Separate trackbacks from comments
  • Separate trackbacks from comments

    Adding this code to your comments.php replacing the default comments loop will allow you to separate trackbacks from comments.

    wordpress snippet : PHP

    <>
    <ul class="commentlist">
        <?php //Displays comments only
    	foreach ($comments as $comment) : ?>
           	<?php $comment_type = get_comment_type(); ?>
           	<?php if($comment_type == 'comment') { ?>
    	    <li>//Comment code goes here</li>
    	<?php }
        endforeach;
    </ul>
    <ul>
        <?php //Displays trackbacks only
    	foreach ($comments as $comment) : ?>
           	<?php $comment_type = get_comment_type(); ?>
           	<?php if($comment_type != 'comment') { ?>
    	    <li><?php comment_author_link() ?></li>
    	<?php }
        endforeach;
    </ul>
    

    ( WordPress codex functions, hooks, in this snippet. )

    get_comment_type, author_link, comment_author, get_comment, trackback,

Build a better with wpsnipp.com

Weekly snippets, themes, deals coupons roundup.

x No Thanks