发布作者: Charlotte
百度收录: 正在检测是否收录...
作品采用: 《 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 》许可协议授权
更新了评论去用户ip归属地显示功能,详情和教程如下。
效果图
实现这样的功能有两种方式,一种是自己编写方法引用,另一种是插件管理,我使用的是第二种。
第一种
本获取不支持IPV6地址
只支持IPV4 调用纯真本地数据库 需要定时更新
要不然 获取可能不准确
首先找到主题的function.php文件
这里我以Joe主题为例 各个主题的不相同 请自行判断
Joe主题的function.php文件在/Joe/core/function.php
将下载的压缩包解压到core目录下 然后编辑function.php文件
然后在第2行引用这个文件代码
require 'ipdata.class.php';
然后新建一个方法
/** 获取评论者归属地信息 */
function convertip($ip){
echo convertips($ip);
}
写完保存这个文件 再找到评论模板的文件 一般都为comment.php
Joe主题的comment.php文件在/Joe/public/comment.php,
然后插入以下代码即可显示,
<?php echo convertip($comments->ip); ?>
joe主题一般在class="agent"的div中插入
<div class="agent"><?php XQLocation_Plugin::render($comments->ip); ?> · <?php _getAgentOS($comments->agent); ?> · <?php _getAgentBrowser($comments->agent); ?></div>
此方法来自于 晓晴博客
第二种
插件支持IPV6和IPV4归属地获取
并且 为了避免卡顿或者获取失败 数据库都是本地 不调用任何第三方API接口
Joe主题的comment.php文件在/Joe/public/comment.php,class="agent"的div中插入
<div class="agent"><?php XQLocation_Plugin::render($comments->ip); ?> · <?php _getAgentOS($comments->agent); ?> · <?php _getAgentBrowser($comments->agent); ?></div>
插入代码
<?php XQLocation_Plugin::render($comments->ip); ?>
(此项也适用于后台)
此方法来自于 晓晴博客
—— 评论区 ——