两种方法实现评论显示UV标识,浏览器、系统、国家

最近一直在折腾一下东西,看到人家的评论区花花绿绿觉得很好玩,于是自己开始折腾评论显示UV标识,百度搜索大多都是插件,本人比较强迫症

所以对网上的代码进行了一下重新组合,完全也是版运工。

下面的方式都是以DUX1.7为例,如果自己用的其他主题自己可以琢磨一下,也欢迎留言咨询!

方法一:

第一种方式显示比较齐全,浏览器、系统、国家都是以图表方式显示。

先找到自己主题的functions.php,这个不用多说,每个主题都有,吧下面的代码复制到里面一定在在<?php?>之间。

require get_stylesheet_directory() . '/ua-show.php';

然后下载这下面的文件,将ip2c文件夹放到主题更目录,flagsbrowsers文件夹放到主题img文件夹下,把ua-show.php文件放到主题根目录

文件下载  文件名称:所需文件  文件大小:597kb
  下载声明:本站文件大多收集于互联网,如有版权问题,请联系博主及时删除!
  下载地址:下载所需文件   ua-show
找到大前端主题modules文件夹下的mo_comments_list.php文件将下面代码添加到echo _get_time_ago($comment->comment_date);代码下
其他主题有可能在functions.php文件里,可以在文件里搜索comment_list然后添加在相应位置
CID_print_comment_flag(); echo ' ';CID_print_comment_browser();
完成效果如下:

方法二:

这个是我从GIT主题里面移出来,显示是以文字方式,也比较简单把下面代码放进functions.php文件里
function user_agent($ua) {
 //开始解析操作系统
 $os = null;
 if (preg_match('/Windows NT 6.0/i', $ua)) {
 $os = "Windows Vista";
 } elseif (preg_match('/Windows NT 6.1/i', $ua)) {
 $os = "Windows 7";
 } elseif (preg_match('/Windows NT 6.2/i', $ua)) {
 $os = "Windows 8";
 } elseif (preg_match('/Windows NT 6.3/i', $ua)) {
 $os = "Windows 8.1";
 } elseif (preg_match('/Windows NT 10.0/i', $ua)) {
 $os = "Windows 10";
 } elseif (preg_match('/Windows NT 5.1/i', $ua)) {
 $os = "Windows XP";
 } elseif (preg_match('/Windows NT 5.2/i', $ua) && preg_match('/Win64/i', $ua)) {
 $os = "Windows XP 64 bit";
 } elseif (preg_match('/Android ([0-9.]+)/i', $ua, $matches)) {
 $os = "Android " . $matches[1];
 } elseif (preg_match('/iPhone OS ([_0-9]+)/i', $ua, $matches)) {
 $os = 'iPhone ' . $matches[1];
 } else {
 $os = '未知操作系统';
 }
 if (preg_match('#(Camino|Chimera)[ /]([a-zA-Z0-9.]+)#i', $ua, $matches)) {
 $browser = 'Camino ' . $matches[2];
 } elseif (preg_match('#SE 2([a-zA-Z0-9.]+)#i', $ua, $matches)) {
 $browser = '搜狗浏览器 2' . $matches[1];
 } elseif (preg_match('#360([a-zA-Z0-9.]+)#i', $ua, $matches)) {
 $browser = '360浏览器 ' . $matches[1];
 } elseif (preg_match('#Maxthon( |\/)([a-zA-Z0-9.]+)#i', $ua, $matches)) {
 $browser = 'Maxthon ' . $matches[2];
 } elseif (preg_match('#Chrome/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
 $browser = 'Chrome ' . $matches[1];
 } elseif (preg_match('#XiaoMi/MiuiBrowser/([0-9.]+)#i', $ua, $matches)) {
 $browser = '小米浏览器 ' . $matches[1];
 } elseif (preg_match('#Safari/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
 $browser = 'Safari ' . $matches[1];
 } elseif (preg_match('#opera mini#i', $ua)) {
 preg_match('#Opera/([a-zA-Z0-9.]+)#i', $ua, $matches);
 $browser = 'Opera Mini ' . $matches[1];
 } elseif (preg_match('#Opera.([a-zA-Z0-9.]+)#i', $ua, $matches)) {
 $browser = 'Opera ' . $matches[1];
 } elseif (preg_match('#TencentTraveler ([a-zA-Z0-9.]+)#i', $ua, $matches)) {
 $browser = '腾讯TT浏览器 ' . $matches[1];
 } elseif (preg_match('#UCWEB([a-zA-Z0-9.]+)#i', $ua, $matches)) {
 $browser = 'UCWEB ' . $matches[1];
 }elseif (preg_match('#wp-(iphone|android)/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
 $browser = 'WordPress客户端 ' . $matches[1];
 } elseif (preg_match('#MSIE ([a-zA-Z0-9.]+)#i', $ua, $matches)) {
 $browser = 'Internet Explorer ' . $matches[1];
 } elseif (preg_match('#(Firefox|Phoenix|Firebird|BonEcho|GranParadiso|Minefield|Iceweasel)/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
 $browser = 'Firefox ' . $matches[2];
 } else {
 $browser = '未知浏览器';
 }
 return $os . " | " . $browser;
 }
找到大前端主题modules文件夹下的mo_comments_list.php文件将下面代码添加到echo _get_time_ago($comment->comment_date);代码下
echo '<span style="color: #ff6600;"> ' . user_agent($comment->comment_agent) . '</span>';
效果如下:
阅读全文
 收藏 (2) 打赏

您可以选择一种方式赞助本站

支付宝扫一扫赞助

微信钱包扫描赞助

未经允许不得转载:轻语博客 » 两种方法实现评论显示UV标识,浏览器、系统、国家
分享到: 生成海报
qux主题真好用,功能强大,界面美观,还一直在更新.....

热门推荐

评论 6

评论前必须登录!

立即登录   注册

  1. #5

    那……帝国怎么用呢

    伍林堂GM−李栋梁5年前 (2018-11-07)国内网友QQ浏览器 Windows 10 登录以回复 举报评论
  2. #4

    贵站博主加下QQ好木?

    GC博客7年前 (2017-01-28)国内网友谷歌浏览器  8681-M02 Build/LMY47D) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/35.0.1916.138 Mobile Safari/537.36 T7/7.5 baidubrowser/7.5.22.0 (Baidu 登录以回复 举报评论
  3. #3

    签到成功!签到时间:2017/1/16 下午11:15:56,每日打卡,生活更精彩哦~

    admin7年前 (2017-01-16)国内网友谷歌浏览器 Windows 7 登录以回复 举报评论
  4. #2

    签到成功!签到时间:2017/1/2 上午8:59:50,每日打卡,生活更精彩哦~

    admin7年前 (2017-01-02)国内网友谷歌浏览器 Windows 7 登录以回复 举报评论
  5. #1

    阿迪达斯

    koko7年前 (2017-01-01)国内网友谷歌浏览器 Windows 7 登录以回复 举报评论

本站承接WordPress主题开发,主题定制,功能开发

QQ咨询轻语云
切换注册

登录

忘记密码 ?

您也可以使用第三方帐号快捷登录

切换登录

注册

我们将发送一封验证邮件至你的邮箱, 请正确填写以完成账号注册和激活

微信扫一扫关注
如已关注,请回复“登录”二字获取验证码