WordPress教程 · WPtech

WordPress评论单独统计显示访客和博主及引用

小编 · 11月18日 · 2019年

HotNews Pro主题评论提示信息,显示为总的评论数,并单独统计显示访客和博主及来至外部的引用。在此基础上陨落de芳菲童鞋又提供了一段有趣的提示信息代码,显示效果:目前有 314 条留言 其中:访客:240 条, 博主:70 条 访客以 240:70 大幅领先博主 外部引用: 4 虽然目前还未想好如何编排,不过这个统计信息确实很有个性。

WordPress评论单独统计显示访客和博主及引用

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, " 条 ";   
        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 大幅领先博主 外部引用:

虽然目前还未想好如何编排,不过这个统计信息确实很有个性。用上面代码替换主题评论模版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, " 条 ";   
?>  
0 条回应

必须 注册 为本站用户, 登录 后才可以发表评论!