I was trying to figure out the best way to separate trackbacks/pings from the comments here on the site. I’ve seen a number of tutorials out there, but none seemed to do exactly what I wanted. The code is piece-mealed from a couple of places, but this is how I accomplished it here on the site:
Backup your existing comments.php
file associated with your theme! I cannot stress this enough.
Assuming you’re using the default theme, or some variation thereof, you’re going to want to look for this in your comments.php
file:
[php]
< ?php if ($comments) : ?>
[/php]
You’re basically going to replace the logic on comments.php
from where it says < ?php if ($comments) : ?>
(Line 20) to < ?php endif; ?>
(Line 61) with the logic below.
Define the number of pings and comments (Source: Sandbox theme):
[php]
< ?php /* NUMBERS OF PINGS AND COMMENTS */
$ping_count = $comment_count = 0;
foreach ( $comments as $comment )
get_comment_type() == "comment" ? ++$comment_count : ++$ping_count;
?>
[/php]
Then check to see whether comment_status
is set to 'open'
. If it is 'open'
, we then check to make sure the comment_count
isn’t equal to zero. Once these conditions are met, I then display only the comments. Some other conditional logic is included, like checking whether the comment’s being held for moderation:
[php]
< ?php if ('open' == $post-> comment_status) : ?>
< ?php if ( $comment_count ) : ?>
< ?php if ($comments) : ?>
< ?php if (get_comment_type() == "comment"){ ?>