前言
如今,许多平台(如抖音、微博、快手等)都已应用了评论显示地区、国家、浏览器以及设备类型(手机或电脑)的功能。
在本教程中,我将教大家如何修改我们的子比主题,以便显示评论的地区和设备信息。相关代码已为大家准备好,只需上传即可使用。废话不多说,直接进入教程!
操作教程
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>';
完成设置
按照以上步骤操作后,您将成功配置子比主题显示评论的地区和使用设备信息。
代码包
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
暂无评论内容