WordPress 显示评论者等级并标注友链邻居和博主身份
这段代码可以根据评论者的评论数显示等级或 VIP 样式,并能标注显示博主的回复,这样的做法以来可以增加用户将互动,毕竟有些网友是很有虚荣心的,如果能显示自己的等级,会吸引更多的回访和提高等级。同时如果是友情链接中的 url,则会显示为邻居,具体代码,可以根据需要自行修改:
-
// 获取访客VIP样式
-
function get_author_class($comment_author_email, $comment_author_url)
-
{
-
global $wpdb;
-
$adminEmail = get_bloginfo('admin_email');
-
$styleClass = 'your css style'; //添加css样式
-
$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 href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="' . $styleClass . ' icon-vip vip7" title="博主"></a><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" title="博主" class="icon-vip icon-admin"></a>';
-
}
-
$linkurls = $wpdb->get_results("SELECT link_url FROM $wpdb->links WHERE link_url = '$comment_author_url'");
-
if ($author_count >= 1 && $author_count < 10 && $comment_author_email != $adminEmail) {
-
echo '<a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="' . $styleClass . ' icon-vip vip1" title="评论达人 LV.1"></a>';
-
} elseif ($author_count >= 10 && $author_count < 20 && $comment_author_email != $adminEmail) {
-
echo '<a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="' . $styleClass . ' icon-vip vip2" title="评论达人 LV.2"></a>';
-
} elseif ($author_count >= 20 && $author_count < 30 && $comment_author_email != $adminEmail) {
-
echo '<a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="' . $styleClass . ' icon-vip vip3" title="评论达人 LV.3"></a>';
-
} elseif ($author_count >= 30 && $author_count < 50 && $comment_author_email != $adminEmail) {
-
echo '<a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="' . $styleClass . ' icon-vip vip4" title="评论达人 LV.4"></a>';
-
} elseif ($author_count >= 50 && $author_count < 80 && $comment_author_email != $adminEmail) {
-
echo '<a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="' . $styleClass . ' icon-vip vip5" title="评论达人 LV.5"></a>';
-
} elseif ($author_count >= 80 && $author_coun < 200 && $comment_author_email != $adminEmail) {
-
echo '<a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="' . $styleClass . ' icon-vip vip6" title="评论达人 LV.6"></a>';
-
} elseif ($author_count >= 200 && $comment_author_email != $adminEmail) {
-
echo '<a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="' . $styleClass . ' icon-vip vip7" title="评论达人 LV.7"></a>';
-
}
-
foreach ($linkurls as $linkurl) {
-
if ($linkurl->link_url == $comment_author_url) {
-
echo '<a class="vp" target="_blank" href="/links/" rel="external nofollow" title="隔壁邻居的哦!" rel="noopener">隔壁邻居的哦!</a>';
-
}
-
}
-
}
这里将代码添加到当前主题 Functions.php 中。
同时,我们需要将下面代码添加到”<?php comment_author_link();?>”评论模板下面。
-
<?php get_author_class($comment->comment_author_email,$comment->comment_author_url,$comment->user_id)?>
如果需要加上博主认证的,需要加上:
-
<?php get_author_class($comment->comment_author_email,$comment->user_id)?>
-
<?php if(user_can($comment->user_id, 1)){echo "<a title='博主认证' class='vip'></a>";}; ?>
我们还需要添加样式:
-
/**博客VIP评论样式**/
-
.vp,.vip,.vip1,.vip2,.vip3,.vip4,.vip5,.vip6,.vip7{background: url(images/vip.png) no-repeat;display: inline-block;overflow: hidden;border: none;}
-
.vp{background-position:-515px -3px;width: 14px;height: 14px;margin-bottom: -2px;}
-
.vip{background-position:-495px -2px;width: 15px;height: 16px;margin-bottom: -3px;}
-
.vip1{background-position:-1px -2px;width: 46px;height: 14px;margin-bottom: -1px;}
-
.vip2{background-position:-63px -2px;width: 46px;height: 14px;margin-bottom: -1px;}
-
.vip3{background-position:-144px -2px;width: 46px;height: 14px;margin-bottom: -1px;}
-
.vip4{background-position:-227px -2px;width: 46px;height: 14px;margin-bottom: -1px;}
-
.vip5{background-position:-331px -2px;width: 46px;height: 14px;margin-bottom: -1px;}
-
.vip6{background-position:-441px -2px;width: 46px;height: 14px;margin-bottom: -1px;}
-
.vip7{background-position:-611px -2px;width: 46px;height: 14px;margin-bottom: -1px;}
这里,我们需要添加图片,配合样式中调用的图片(images/vip.png)。
-
本站资源均来源于网络或网友投稿,部分资源未经测试,难免存在BUG,所有资源只限于学习研究,不得商用。如使用本站下载的资源造成任何损失或发生侵权行为,均与本站无关。如不接受本声明请勿下载!本站资源如有侵权,请联系QQ:497149677核实后立即删除!
最客资源网 » WordPress 显示评论者等级并标注友链邻居和博主身份
最客资源网 » WordPress 显示评论者等级并标注友链邻居和博主身份