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

主题评论提示信息,显示为总的评论数,并单独统计显示访客和博主及来至外部的引用在此基础上陨落de芳菲童鞋又提供了一段有趣的提示信息代码
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, " 条 ";   
    ?>  
Wordpress

WordPress主题集成图片暗箱特效

2021-10-18 17:28:00

Wordpress

安全提示:主题是否使用了自动缩略图脚本timthumb.php

2021-10-20 20:54:00

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索