子比主题添加评论链接填写框[已实装]

参考登山亦有道博客的文章《子比主题评论区添加网址填写框

修改 comments.php 文件

文件位置 wp-content/themes/zibll/template/comments.php

搜索 邮箱 找到评论区填写框位置,代码添加位置如图所示。

图片[1] - 子比主题添加评论链接填写框[已实装] - 云晓晨 KaiQi.Wang
  1. 修改邮箱的class值,使得样式一致。
  2. 添加链接填写框。

修改 zib-comments-list.php 文件

文件位置 /wp-content/themes/zibll/inc/functions/zib-comments-list.php

找到 zib_get_comments_user_name 函数,修改为以下内容。

//获取主评论的评论用户姓名
function zib_get_comments_user_name($comment)
{
    if (!$comment) {
        return;
    }

    $user_id   = $comment->user_id;
    $user_name = '';
    if ($user_id) {
        $user = get_userdata($user_id);
        if (isset($user->display_name)) {
            $display_name = $user->display_name;
            $url          = zib_get_user_home_url($user_id);
            $user_name    = '<a class="text-ellipsis font-bold" href="' . $url . '">' . $display_name . '</a>';
            $user_name .= zib_get_user_auth_badge($user_id, 'ml3');
            $user_name .= zib_get_medal_wear_icon($user_id, 'ml3');
            $user_name .= zib_get_user_level_badge($user_id, 'ml3');
        }
    }

    $user_name     = $user_name ? $user_name : '<b class="mr6">' . $comment->comment_author . '</b>';
    
    // 初始化用户名称(用户或访客)
    $user_name = $user_name ? $user_name : '<b class="mr6">' . $comment->comment_author . '</b>';
    
    // 新增:处理评论作者URL和作者标签
    $author_url = get_comment_author_url($comment->comment_ID);
    if (!empty($author_url) && $author_url !== 'http://' && $author_url !== 'https://') {
        // 如果存在作者URL,添加外部链接
        $user_name = '<a target="_blank" href="' . esc_url($author_url) . '">' . $user_name . '</a>';
    }
    
    $badge         = '';
    $topping_badge = '';
    //置顶
    if (!empty($comment->topping)) {
        $topping_badge = '<badge class="badge-topping badge-topping jb-blue mr6 flex0" title="置顶评论" data-toggle="tooltip">' . zib_get_svg('topping') . '</badge>';
    }

    if ($user_id && _pz('comment_author_tag', true)) {
        $post = get_post($comment->comment_post_ID);
        if ($user_id == $post->post_author) {
            $badge .= '<span class="badg c-green badg-sm flex0 ml3">作者</span>';
        }
    }
    $badge = apply_filters('comments_user_name_badge', $badge, $comment);

    return '<name class="flex ac flex1">' . $topping_badge . $user_name . $badge . '</name>';
}
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发
访客头像 - 云晓晨 KaiQi.Wang
欢迎您留下宝贵的见解!
提交
访客头像 - 云晓晨 KaiQi.Wang

昵称

取消
昵称表情代码图片快捷回复

    暂无评论内容