子比主题评论等级添加

前言
这几天有很多人想让我出个评论区等级铭牌的教程,因子比主题要大更新出论坛系统了,想着就不分享出来了,不过还是写出来给大家吧,说不定也有人用的上!话不多说先来看看效果图。(刚写完就在小伙伴那里发现一个问题【站长没开通vip的话会显示新朋友】,所以更新了一下)

图片

图片[1]-子比主题评论等级添加-梦都歌-精品资源社区,梦都歌资源网

步骤一

主要代码还是在zibll/inc/functions/zib-comments-list.php里面,网站评论区有点冷清我就设置个评论才能看吧!

zib-bomments-list文件

搜索找到 if ($user_id == $post->post_author) 在上面添加代码

 

搜索找到 echo $user_name 在下面添加代码

if (_pz('user_comment_level', true)) {
            //评论区评论等级开始
            $com_n = (int) get_user_comment_count($user_id); //获取用户评论次数
            echo xypro_user_comment_level_badge($user_id, 'ml3'); //添加评论徽章
            xypro_update_user_comment_level($user_id, $com_n); //刷新评论等级
        
            if (!$user_id && _pz('pass_icon', true)) {
                echo '<img class="img-icon ml3 ls-is-cached lazyloaded" src="'.$pass.'" data-src="'.$pass.'" data-toggle="tooltip" alt="路人" data-original-title="路人">';
            }
            //评论区评论等级结束
        }

 

functions文件

//获取用户评论等级
function xypro_user_comment_level($id = 0)
{
    if (!$id) {
        return false;
    }
    $level = (int) get_user_meta($id, 'comment_level', true);
    if (!$level) {
        //初始等级1
        update_user_meta($id, 'comment_level', 1);
        $level = 1;
    }
    $max = _pz('comment_level_max', 7);
    return $level > $max ? $max : $level;
}
//用户获取评论等级徽章
function xypro_user_comment_level_badge($id = 0, $class = '', $tip = true)
{
    if (!$id || !_pz('user_comment_level', true)) {
        return;
    }
    $user_level = xypro_user_comment_level($id);
    return xypro_comment_level_badge($user_level, $class, $tip);
}
//用户获取评论等级徽章
function xypro_comment_level_badge($user_level = 0, $class = '', $tip = true)
{
    if (!$user_level) {
        return;
    }
    $icon_url  = _pz('comment_level_opt', 'https://kpi.21lhz.cn/images/lv/' . $user_level . '.png', 'comment_level_icon_' . $user_level);
    $title     = esc_attr(_pz('comment_level_opt', 'LV' . $user_level, 'comment_name_' . $user_level));
    $tip_attr  = $tip ? ' data-toggle="tooltip"' : '';
    $lazy_attr = zib_get_lazy_attr('lazy_other', $icon_url, 'img-icon ' . $class, ZIB_TEMPLATE_DIRECTORY_URI . '/img/thumbnail-null.svg');
    $vip_badge = '<img ' . $lazy_attr . $tip_attr . ' title="' . esc_attr(strip_tags($title)) . '" alt="' . esc_attr(strip_tags($title)) . '">';
    return $vip_badge;
}
//更新用户评论等级
function xypro_update_user_comment_level($user_id, $_meta_value)
{
    $_meta_value = (int) $_meta_value; //评论次数
    $user_level  = xypro_user_comment_level($user_id); //用户评论等级
    $user_level  = $user_level ? $user_level : 1;
    $level_max   = _pz('comment_level_max', 7); //最大等级
    $new_level   = $user_level;
    if ($_meta_value < (int) _pz('comment_level_opt', 0, 'comment_upgrade_integral_' . ($user_level + 1))) {
        return;
    }
    if ($_meta_value >= (int) _pz('comment_level_opt', 0, 'comment_upgrade_integral_' . $level_max)) {
        $new_level = $level_max;
    } else {
        for ($i = $user_level; $i <= $level_max; $i++) {
            $upgrade   = (int) _pz('comment_level_opt', 0, 'comment_upgrade_integral_' . $i);
            $upgrade_n = (int) _pz('comment_level_opt', 0, 'comment_upgrade_integral_' . ($i + 1));
            if ($_meta_value >= $upgrade && $_meta_value < $upgrade_n) {
                $new_level = $i;
                break;
                //达到升级要求
            }
        }
    }
    if ($new_level != $user_level) {
        update_user_meta($user_id, 'comment_level', $new_level);
    }
}

 

步骤二

这里需要还有两处添加,分别是 admin-options 跟 options-module ,我们一步一步来,最后会放文件具体位置!

文件路径

functions.php 在 zibll/funtions.php

zib-comments-list.php 在 zibll/inc/functions

admin-options.php 在 zibll/inc/options

options-module.php 在 zibll/inc/options

结束

因为子比主题更新之前的已经无用,这里重新更新一下,等级数据添加到后台设置了!添加完代码后在后台找到 用户&互动 -> 评论等级 保存一下!

温馨提示:本文最后更新于2024-08-09 17:19:26,某些文章具有时效性,若有错误或已失效,请在下方留言或联系梦歌社长
© 版权声明
THE END
喜欢就支持一下吧
点赞5赞赏 分享
评论 共2条

请登录后发表评论

    • y1683075866的头像-梦都歌-精品资源社区,梦都歌资源网y1683075866徽章-社交达人-梦都歌-精品资源社区,梦都歌资源网等级-LV1-梦都歌-精品资源社区,梦都歌资源网评论等级:Lv.1 靓号:0000220
    • 梦歌的头像-梦都歌-精品资源社区,梦都歌资源网星梦大会员梦歌徽章-先富之人-梦都歌-精品资源社区,梦都歌资源网等级-LV10-梦都歌-精品资源社区,梦都歌资源网评论等级:Lv.1作者 靓号:0000010