分享一段有趣的评论统计信息代码
HotNews Pro主题评论提示信息,显示为总的评论数,并单独统计显示访客和博主及来至外部的引用,显示效果如下:
目前有 314 条留言 其中:访客:240 条, 博主:70 条 引用: 4
<h2 id="comments">目前有
<?php
$my_email = get_bloginfo ( 'admin_email' );
$str = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = $post->ID
AND comment_approved = '1' AND comment_type = '' AND comment_author_email";
$count_t = $post->comment_count;
$count_v = $wpdb->get_var("$str != '$my_email'");
$count_h = $wpdb->get_var("$str = '$my_email'");
echo $count_t, " 条留言 其中:访客:", $count_v, " 条, 博主:", $count_h, " 条 ";
?>