May 23, 2006
6:58 pm | Last updated: May 23, 2006 at: 7:47 pm

[php] $bm_trackbacks ="" array();
$bm_comments ="" array();

function split_comments( $source ) {

if ( $source ) foreach ( $source as $comment ) {

global $bm_trackbacks;
global $bm_comments;

if ( $comment->comment_type == ‘trackback’ || $comment->comment_type == ‘pingback’ ) {
$bm_trackbacks[] = $comment;
} else {
$bm_comments[] = $comment;
}
}
} ?>[/php]

What the code is doing is looping through all the comments and splitting them into two new variables which are separately the comments and trackbacks for the post.

To use it you add the following before your comment loop:

[php] global $bm_comments;
global $bm_trackbacks;

split_comments( $comments ); ?>[/php]

And then you can use the new comments the same way you always have:

[php]

// --------
// comments
// --------

foreach ( $bm_comments as $comment ) {
// comment display code (exactly the same as you use at the moment)
}

// ----------
// trackbacks
// ----------

// check there actually are some trackbacks
if ( count( $bm_trackbacks ) > 0 ) {

// I like to add a separate heading here

foreach ( $bm_trackbacks as $comment ) { ?>
// trackback display code (I only display a link to the site and no message content)
}

}

?>[/php]

Now that I have typed all that out it looks a lot bigger and more complicated than I intended. Hopefully it’s clean enough for someone to get some use from it.

Pages: 1 2

Related Posts:

No followup yet

Leave a Response

Comment Preview

« Turbo Charger Portable AA Cell ChargerShow message about Comment moderation »

Feed Icon