加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > CMS系统 > wordpress > 正文

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

发布时间:2020-12-14 14:24:17 所属栏目:wordpress 来源:网络整理
导读:由站长 通过网络收集整理的代码片段。编程之家小编现在分享给大家,也给大家做个参考。 给 wordpress 评论者添加等级显示,在一定程度上能够刺激用户发言的积极性,今天雅兮网就分享下目前在用的评论样式以及实现代码!作为一个博客型站点,

以下代码由PHP站长网 52php.cn收集自互联网现在PHP站长网小编把它分享给大家,仅供参考

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



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

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

//评论VIP标志

function get_author_class($comment_author_email,$comment_author_url){

global $wpdb;

$adminEmail = '此处写入站长邮箱';

$author_count = count($wpdb->get_results(

"SELECT comment_ID as author_count FROM $wpdb->comments WHERE comment_author_email = '$comment_author_email' "));

if($comment_author_email ==$adminEmail)

echo '<a class="vp" target="_blank" href="/about.html" title="经鉴定,这货是站长"><i class="wi wi-crown"></i><span class="lv">站长</span></a>';

$linkurls = $wpdb->get_results(

"SELECT link_url FROM $wpdb->links WHERE link_url = '$comment_author_url'");

foreach ($linkurls as $linkurl) {

if ($linkurl->link_url == $comment_author_url )

echo '<a class="vip" target="_blank" href="/links.html" title="合作商或友情链接认证"><i class="wi wi-heart"></i></a>';

}

if($author_count>=1 && $author_count<10 && $comment_author_email!=$adminEmail)

echo '<a class="vip1" target="_blank" href="/about.html" title="评论之星 LV.1"><i class="wi wi-level-1"></i></a>';

else if($author_count>=10 && $author_count<20 && $comment_author_email!=$adminEmail)

echo '<a class="vip2" target="_blank" href="/about.html" title="评论之星 LV.2"><i class="wi wi-level-2"></i></a>';

else if($author_count>=20 && $author_count<50 && $comment_author_email!=$adminEmail)

echo '<a class="vip3" target="_blank" href="/about.html" title="评论之星 LV.3"><i class="wi wi-level-3"></i></a>';

else if($author_count>=50 && $author_count<100 && $comment_author_email!=$adminEmail)

echo '<a class="vip4" target="_blank" href="/about.html" title="评论之星 LV.4"><i class="wi wi-level-4"></i>/a>';

else if($author_count>=100 && $author_count<200 && $comment_author_email!=$adminEmail)

echo '<a class="vip5" target="_blank" href="/about.html" title="评论之星 LV.5"><i class="wi wi-level-5"></i></a>';

else if($author_count>=200 && $author_count<500 && $comment_author_email!=$adminEmail)

echo '<a class="vip6" target="_blank" href="/about.html" title="评论之星 LV.6"><i class="wi wi-level-6"></i></a>';

else if($author_count>=500 && $comment_author_email!=$adminEmail)

echo '<a class="vip7" target="_blank" href="/about.html" title="评论之星 LV.7"><i class="wi wi-level-7"></i></a>';

}

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

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

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

以上内容由PHP站长网【52php.cn】收集整理供大家参考研究如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读