WordPress教程

WordPress评论等级博主及友链认证

阿里云

WordPress 评论者添加等级显示,在一定程度上能够刺激用户发言的积极性,今天雅兮网就分享下目前在用的评论样式以及实现代码!作为一个博客型站点,评论功能起着举足轻重的作用,可以说访客的一言一语让整个站点“活”起来了。这时候适当给评论者加个评论等级,更有种锦上添花的感觉。一方面可以很直观的看到哪些是忠实的读者,另一外面也在一定程度上刺激了读者发言的兴趣。有朋友留言咨询,今天雅兮网就分享下目前在用的评论样式以及实现代码!

上图所示是目前在用的评论等级样式,其中包含评论者等级显示、站长认证、友情链接认证。其原理是查询数据库根据评论者邮箱已评论条数显示不同的内容;友链认证是根据读者填入的链接地址判断是否为友情链接而输出内容;站长认证是判断读者填入的邮箱是否为站长输出内容,为了防止有人冒充站长进行留言,建议开启《WordPress 禁止冒充管理员评论》功能。

至于输出什么内容,本站使用的是直接输出字体图标,您可酌情修改为文字或图片等;将如下代码放入主题函数模板中(functions.php):

也想出现在这里?联系我们
创客主机
  1.     //评论VIP标志
  2.     function get_author_class($comment_author_email,$comment_author_url){
  3.     global $wpdb;
  4.     $adminEmail = '此处写入站长邮箱';
  5.     $author_count = count($wpdb->get_results(
  6.     "SELECT comment_ID as author_count FROM $wpdb->comments WHERE comment_author_email = '$comment_author_email' "));
  7.     if($comment_author_email ==$adminEmail)
  8.     echo '<a class="vp" target="_blank" href="/about.HTML" title="经鉴定,这货是站长"><i class="wi wi-crown"></i><span class="lv">站长</span></a>';
  9.     $linkurls = $wpdb->get_results(
  10.     "SELECT link_url FROM $wpdb->links WHERE link_url = '$comment_author_url'");
  11.     foreach ($linkurls as $linkurl) {
  12.     if ($linkurl->link_url == $comment_author_url )
  13.     echo '<a class="vip" target="_blank" href="/links.html" title="合作商或友情链接认证"><i class="wi wi-heart"></i></a>';
  14.     }
  15.     if($author_count>=1 && $author_count<10 && $comment_author_email!=$adminEmail)
  16.     echo '<a class="vip1" target="_blank" href="/about.html" title="评论之星 LV.1"><i class="wi wi-level-1"></i></a>';
  17.     else if($author_count>=10 && $author_count<20 && $comment_author_email!=$adminEmail)
  18.     echo '<a class="vip2" target="_blank" href="/about.html" title="评论之星 LV.2"><i class="wi wi-level-2"></i></a>';
  19.     else if($author_count>=20 && $author_count<50 && $comment_author_email!=$adminEmail)
  20.     echo '<a class="vip3" target="_blank" href="/about.html" title="评论之星 LV.3"><i class="wi wi-level-3"></i></a>';
  21.     else if($author_count>=50 && $author_count<100 && $comment_author_email!=$adminEmail)
  22.     echo '<a class="vip4" target="_blank" href="/about.html" title="评论之星 LV.4"><i class="wi wi-level-4"></i>/a>';
  23.     else if($author_count>=100 && $author_count<200 && $comment_author_email!=$adminEmail)
  24.     echo '<a class="vip5" target="_blank" href="/about.html" title="评论之星 LV.5"><i class="wi wi-level-5"></i></a>';
  25.     else if($author_count>=200 && $author_count<500 && $comment_author_email!=$adminEmail)
  26.     echo '<a class="vip6" target="_blank" href="/about.html" title="评论之星 LV.6"><i class="wi wi-level-6"></i></a>';
  27.     else if($author_count>=500 && $comment_author_email!=$adminEmail)
  28.     echo '<a class="vip7" target="_blank" href="/about.html" title="评论之星 LV.7"><i class="wi wi-level-7"></i></a>';
  29.     }

将下面函数放入到评论列表模板里,一般放在评论者昵称后面:

  1. <?php get_author_class($comment->comment_author_email,$comment->comment_author_url)?>

样式代码就不贴出来了,大家可根据自己的实际情况,进行修改以及样式调整。刷新页面,是不是已经实现了呢?

WordPress 评论等级博主及友链认证

已有 349 人购买
查看演示升级 VIP立刻购买

收藏
(0)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!