飞流 发表于 2025-10-10 18:08:00

子比主题 – 评论链接直链跳转功能(共两款)

这是一款子比主题评论链接直接跳转的功能,作用就是用户在我们的评论区评论了网站的链接,那么会自动转成超链接,腾飞博客做了两款样式,一个是默认跟主题色,一个是链接下固定下划线,当然你如果有自己的样式也可以写进去!

第一款

第二款

代码部署
定位:/wp-content/themes/zibll/inc/functions/zib-comments-list.php文件,我们搜下面代码!
function zib_comment_filters($cont, $type = '', $lazy = true)然后我们看上面的图片喜欢哪个一款直接替换我的整个函数代码,如下图我圈住的替换即可!


第一款没有样式,是直接跳转的,直接替换整个函数代码即可!
function zib_comment_filters($cont, $type = '', $lazy = true)
{
    $cont = preg_replace_callback('/https?:\/\/+\.{2,3}(\/\S*)?/', function($matches) {
      return '<a href="' . $matches . '" class="comment-link" target="_blank">' . $matches . '</a>';
    }, $cont);
    $cont = convert_smilies($cont);
    $cont = preg_replace('/\/', '<img class="box-img lazyload" src="$1" alt="评论图片' . zib_get_delimiter_blog_name() . '">', $cont);
    if ('noimg' == $type) {
      $cont = preg_replace('/\<img(.*?)\>/', '[图片]', $cont);
      $cont = preg_replace('/\([\s\S]*)\[\/code]/', '[代码]', $cont);
    } else {
      $cont = str_replace('', '<pre><code>', $cont);
      $cont = str_replace('', '</code></pre>', $cont);
    }
    $cont = preg_replace('/\/', '<img class="smilie-icon" src="' . ZIB_TEMPLATE_DIRECTORY_URI . '/img/smilies/$1.gif" alt="表情[$1]' . zib_get_delimiter_blog_name() . '">', $cont);

    if (zib_is_lazy('lazy_comment') && $lazy) {
      $cont = str_replace(' src=', ' src="' . zib_get_lazy_thumb() . '" data-src=', $cont);
    }
    $cont = wp_kses_post($cont);
    return $cont;
}


第二款是带有固定波浪的样式,不是动态的,一共两个代码,首先还是替换整个函数代码即可!
function zib_comment_filters($cont, $type = '', $lazy = true) {
    $cont = convert_smilies($cont);

    $cont = preg_replace('/\/', '<img class="box-img lazyload" src="$1" alt="评论图片' . zib_get_delimiter_blog_name() . '">', $cont);
    $pattern = '/(https?:\/\/[^\s]+)/i';
    $replacement = '<a href="$1" target="_blank" class="comment-link" style="color: var(--focus-color);">$1</a>';
    $cont = preg_replace($pattern, $replacement, $cont);
    if ('noimg' == $type) {
      $cont = preg_replace('/\<img(.*?)\>/', '[图片]', $cont);
      $cont = preg_replace('/\([\s\S]*)\[\/code]/', '[代码]', $cont);
    } else {
      $cont = str_replace('', '<pre><code>', $cont);
      $cont = str_replace('', '</code></pre>', $cont);
    }
    $cont = preg_replace('/\/', '<img class="smilie-icon" src="' . ZIB_TEMPLATE_DIRECTORY_URI . '/img/smilies/$1.gif" alt="表情[$1]' . zib_get_delimiter_blog_name() . '">', $cont);
    if (zib_is_lazy('lazy_comment') && $lazy) {
      $cont = str_replace(' src=', ' src="' . zib_get_lazy_thumb() . '" data-src=', $cont);
    }

    $cont = wp_kses_post($cont);
    return $cont;
}然后第二个代码放到:子比主题–>>自定义CSS样式即可!
/* 评论链接波浪线样式 */
.comment-link {
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
    text-decoration: underline wavy !important;
    text-decoration-thickness: from-font;
    text-underline-offset: 3px;
}
.navbar-top li.current-menu-item>a,
.navbar-top li:hover>a {
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
    text-decoration: underline wavy;
    text-decoration-thickness: from-font;
    text-underline-offset: 3px;
}

页: [1]
查看完整版本: 子比主题 – 评论链接直链跳转功能(共两款)