WordPress评论统计信息代码,为你的文章加上统计 – WordPress 教程

2022年 10月 24日 发表评论
腾讯云正在大促:点击直达 阿里云超级红包:点击领取
免费/便宜/高性价比服务器汇总入口(已更新):点击这里了解

主题评论提示信息,显示为总的评论数,并单独统计显示访客和博主及来至外部的引用在此基础上陨落de芳菲童鞋又提供了一段有趣的提示信息代码

Wordpress评论统计信息代码,为你的文章加上统计 – WordPress 教程
wordpress

WordPress主题评论提示信息,显示为总的评论数,并单独统计显示访客和博主及来至外部的引用,显示效果如下:

目前有 314 条留言 其中:访客:240 条, 博主:70 条 引用: 4

在此基础上陨落de芳菲童鞋又提供了一段有趣的提示信息代码:

<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, " 条 ";           if ($count_v>$count_h) :             if ($count_v-$count_h>=5) :             echo " 访客以 ", $count_v, ":", $count_h, " 大幅领先博主 ", "";             elseif ($count_v-$count_h<5) :                 echo " 访客以 ", $count_v, ":", $count_h, " 暂时领先博主 ", "";             endif;           elseif ($count_v<$count_h) :             if ($count_h-$count_v>=5) :             echo " 博主以 ", $count_h, ":", $count_v, " 大幅领先访客 ", "";             elseif ($count_h-$count_v<5) :                 echo " 博主以 ", $count_h, ":", $count_v, " 暂时领先访客 ", "";             endif;           elseif ($count_v==$count_h) :                 if ($count_t==0) :             echo "暂时没有评论,", " 还不<a href='#respond'>快枪沙发</a>? ", "";             else :             echo "目前共有 ",$count_t, " 条评论,双方以 ", $count_v, ":", $count_h, " 暂时持平 ", "";             endif;           endif;       ?>  

显示效果如下:

目前有 314 条留言 其中:访客:240 条, 博主:70 条 访客以 240:70 大幅领先博主 外部引用: 4

虽然目前还未想好如何编排,不过这个统计信息确实很有个性。用上面代码替换主题评论模版comments.php中的:

<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, " 条 ";       ?>  

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: