主题评论提示信息,显示为总的评论数,并单独统计显示访客和博主及来至外部的引用在此基础上陨落de芳菲童鞋又提供了一段有趣的提示信息代码 wordpress WordPress主题评论提示信息,显示为总的评论数,并单独统计显示访客和博主及来至外部的引用,显示效果如下: 目前有 314 条留言 其中:访客:240 条, 博主…

主题评论提示信息,显示为总的评论数,并单独统计显示访客和博主及来至外部的引用在此基础上陨落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, " 条 ";   
    ?>  
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。