自由屋推书网—热门的小说推荐平台!

你的位置: 首页 > wordpress分享

wordpress增加评论者等级标志

2015-11-16 07:57:18

wordpress添加wordpress用户评论等级,这个方法就是根据检测评论人的邮箱留言次数来划分等级,可以更好的增加互动次数!本方法不用插件,直接后台实现添加代码实现,效果如下图:

wordpress用户评论等级

下面开始添加等级代码:

1.找到主题中的functions.php文件并添加下面的代码:

  1. /* WordPress 添加评论之星 */
  2. function get_author_class($comment_author_email,$user_id){
  3. global $wpdb;
  4. $author_count = count($wpdb->get_results(
  5. "SELECT comment_ID as author_count FROM $wpdb->comments WHERE comment_author_email = '$comment_author_email' "));
  6. /*如果不需要管理员显示VIP标签,就把下面一行的 // 去掉*/
  7. // $adminEmail = get_option('admin_email');if($comment_author_email ==$adminEmail) return;
  8. if($author_count>=10 && $author_count<20)
  9. echo '<a class="vip1" title="评论达人 LV.1"></a>';
  10. else if($author_count>=20 && $author_count<40)
  11. echo '<a class="vip2" title="评论达人 LV.2"></a>';
  12. else if($author_count>=40 && $author_count<80)
  13. echo '<a class="vip3" title="评论达人 LV.3"></a>';
  14. else if($author_count>=80 && $author_count<160)
  15. echo '<a class="vip4" title="评论达人 LV.4"></a>';
  16. else if($author_count>=160 && $author_count<320)
  17. echo '<a class="vip5" title="评论达人 LV.5"></a>';
  18. else if($author_count>=320 && $author_count<640)
  19. echo '<a class="vip6" title="评论达人 LV.6"></a>';
  20. else if($author_count>=640)
  21. echo '<a class="vip7" title="评论达人 LV.7"></a>';
  22. }

2.打开主题的评论文件(一般在comments.php 或 functions.php 里),找到:

  1. <?php comment_author_link() ?>

在下面添加以下代码

  1. <?php get_author_class($comment->comment_author_email,$comment->user_id);?>
  2. <?php if(user_can($comment->user_id, 1)){echo "<a title='博主' class='vip'></a>";};?>

3.下载下面的图片到你的主题images文件夹里

4.在主题的 style.css 文件的最后,添加下面的样式代码:

  1. /*VIP评论之星*/
  2. .vp,.vip,.vip1,.vip2,.vip3,.vip4,.vip5,.vip6,.vip7{backgroundurl(images/vip.png) no-repeat;displayinline-block;overflowhidden;bordernone;}
  3. .vp{background-position:-515px -2px;width16px;height16px;margin-bottom: -3px;}
  4. .vp:hover{background-position:-515px -22px;width16px;height16px;margin-bottom: -3px;}
  5. .vip{background-position:-494px -3px;width16px;height14px;margin-bottom: -2px;}
  6. .vip:hover{background-position:-494px -22px;width16px;height14px;margin-bottom: -2px;}
  7. .vip1{background-position:-1px -2px;width46px;height14px;margin-bottom: -1px;}
  8. .vip1:hover{background-position:-1px -22px;width46px;height14px;margin-bottom: -1px;}
  9. .vip2{background-position:-63px -2px;width46px;height14px;margin-bottom: -1px;}
  10. .vip2:hover{background-position:-63px -22px;width46px;height14px;margin-bottom: -1px;}
  11. .vip3{background-position:-144px -2px;width46px;height14px;margin-bottom: -1px;}
  12. .vip3:hover{background-position:-144px -22px;width46px;height14px;margin-bottom: -1px;}
  13. .vip4{background-position:-227px -2px;width46px;height14px;margin-bottom: -1px;}
  14. .vip4:hover{background-position:-227px -22px;width46px;height14px;margin-bottom: -1px;}
  15. .vip5{background-position:-331px -2px;width46px;height14px;margin-bottom: -1px;}
  16. .vip5:hover{background-position:-331px -22px;width46px;height14px;margin-bottom: -1px;}
  17. .vip6{background-position:-441px -2px;width46px;height14px;margin-bottom: -1px;}
  18. .vip6:hover{background-position:-441px -22px;width46px;height14px;margin-bottom: -1px;}
  19. .vip7{background-position:-611px -2px;width46px;height14px;margin-bottom: -1px;}
  20. .vip7:hover{background-position:-611px -22px;width46px;height14px;margin-bottom: -1px;}

5.保存刷新去看一下你的留言就OK了!

本文非原创,原文地址:www.wpdaxue.com/wp-comments-vip.html

编辑推荐

热门小说