Um, another function that assumes all three are comments:
<?php $numOfComments = get_comments_number(); echo $numOfComments; ?>
For example it will print “5” when there is 3 trackbacks and 2 comments. 🙁
Anyone got any ideas on how I can do this at least?
That’s pretty much the way things are: Comments, trackbacks and pingbacks are all treated the same.
If you want to Present them differently, you certainly can. That’s something you do at the theme (presentation) level.
For instance, I show all my trackbacks/pingbacks in a list first, then the comments.
Yes that is what I do now, but I just want to count them as what they really are. For example a topic has 15 comments, 5 trackbacks, and 3 pingbacks. Not 23 comments.
Well… if you lump track/ping backs together, you could do something like this:
<?php /* Count the totals */
$numPingBacks = 0;
$numComments = 0;
foreach ($comments as $comment) {
if (get_comment_type() != "comment") {
$numPingBacks++;
} else {
$numComments++;
}
}
?>
Hi,
Thanks, that works on comments.php within the loop, but not outside the loop, like on post.php.
Sorry, should have mentioned it, I am looking to display the number of comments, number of trackbacks, and number of pingbacks, for each post via post.php outside the loop.
Also, I noticed the above code works fine for comments but it treats trackbacks and pingbacks as one. Anyway to separate the two?
Thanks again,
Will
I don’t have the entire answer, but maybe this’ll get you closer…
On my blog, this query:
SELECT comment_type, count( comment_type )
FROM <code>wp_comments</code>
WHERE comment_post_id =937
GROUP BY comment_type
(where 937 = post_id) results in:
Count comment_type count( comment_type )
30
pingback 63
trackback 3
(pardon the formatting).
Comments are blank. But pingback/trackbacks are differentiated at the db level, so there’s hope…
Hey,
I got to really learn PHP and mysql one of these days… lol
I am sure this sucks big time and it is much easier than this:
<?php
$numberOfComments = $wpdb->get_var("SELECT COUNT( comment_post_ID ) FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND comment_type = '' GROUP BY 'comment_type' ");
$numberOfTrackbacks = $wpdb->get_var("SELECT COUNT( comment_post_ID ) FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND comment_type = 'trackback' GROUP BY 'comment_type' ");
$numberOfPingbacks = $wpdb->get_var("SELECT COUNT( comment_post_ID ) FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND comment_type = 'pingback' GROUP BY 'comment_type' ");
if ($numberOfComments != "" && $numberOfComments == 1) {
echo $numberOfComments; echo " comment ";
} else if ($numberOfComments > 1) {
echo $numberOfComments; echo " comments ";
}
if ($numberOfTrackbacks != "" && $numberOfTrackbacks == 1) {
echo $numberOfTrackbacks; echo " trackback ";
} else if ($numberOfTrackbacks > 1) {
echo $numberOfTrackbacks; echo " trackbacks ";
}
if ($numberOfPingbacks != "" && $numberOfPingbacks == 1) {
echo $numberOfPingbacks; echo " comment ";
} else if ($numberOfPingbacks > 1) {
echo $numberOfPingbacks; echo " comments ";
}
?>
Take Care,
Will
Hi,
Thanks, that works on comments.php within the loop, but not outside the loop, like on post.php.
Sorry, should have mentioned it, I am looking to display the number of trackbacks, and number of pingbacks, for each post .
please help me
I dont m8. I need some help still too…