如有任何问题请联系博主,还请诸位大佬多多关照!!!
       添加博主
详情
评论
问答

子比主题美化-评论显示IP地区和设备类型配置

前言

如今,许多平台(如抖音、微博、快手等)都已应用了评论显示地区、国家、浏览器以及设备类型(手机或电脑)的功能。

在本教程中,我将教大家如何修改我们的子比主题,以便显示评论的地区和设备信息。相关代码已为大家准备好,只需上传即可使用。废话不多说,直接进入教程!

操作教程

1. 下载代码包

首先,下载我们的代码包。如果您使用的主题是 zibll,请将 RAR 包上传到 wp-content/themes/zibll/ 目录下,同时在网站根目录也复制一份 show-useragent 文件。

2. 上传代码

将压缩包上传到主题的根目录,注意不要上传到 WordPress 的根目录。

3. 修改function.php

在 PHP 作用域内,打开 function.php 文件,添加以下两行代码:

include<strong>(</strong>"show-useragent/show-useragent.php"<strong>)</strong>;   // 显示访客信息include<strong>(</strong>"show-useragent/ip2c-text.php"<strong>)</strong>;        // IP归属地和运营商查询功能

4. 替换评论列表代码

在 /wp-content/themes/zibll/inc/functions/zib-comments-list.php 文件的第 51 行,找到以下代码并进行替换:

return '<name class="flex ac flex1">';

替换为:

$ip = convertip<strong>(</strong>get_comment_author_ip<strong>())</strong>;return '<name class="flex ac flex1">' . $user_name . $badge . '<span class="badg badge badg-sm flex0 ml3">' . $ip . '</span>' . '</name>';

5. 修改时间显示代码

接下来,搜索 $time_html,在第一个 //时间 处直接替换代码:

$diqu = CID_get_comment_browser<strong>()</strong>;$diqu .= CID_print_comment_flag<strong>()</strong>;$time_html = '<span class="comt-author"' . <strong>(</strong>$is_mobile ? ' data-toggle="tooltip"' <strong>:</strong> ''<strong>)</strong> . ' title="' . date<strong>(</strong>'Y年m月d日 H:i:s', strtotime<strong>(</strong>$comment-<strong>></strong>comment_date<strong>))</strong> . '">' . zib_get_time_ago<strong>(</strong>$comment-<strong>></strong>comment_date<strong>)</strong> . '</span>' . '<span class="comt-author" title="">' . $diqu . '</span>';

完成设置

按照以上步骤操作后,您将成功配置子比主题显示评论的地区和使用设备信息。

代码包

© 版权声明
THE END
喜欢就支持一下吧
点赞13 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容