- 资源介绍
- 更新记录
- 安装教程
Ripro美化-评论框显示用户浏览器及操作系统信息
之前网站上分享过一篇 RIPRO主题评论添加VIP星级与博主认证 当然了,这篇文章的代码不单单适用于RIPRO主题,对于一些其他的主题来说也是同样使用的,之所以这么命名是因为当时文章写的比较匆忙,没有对其他主题进行测试,本着对每一位网站浏览者负责的态度便这么命名了,而我这次分享的评论框显示用户浏览器及操作系统本人已经测试过几款不同的WordPress主题了,表示显示起来并没有发现什么问题。
这次对主题的修改操作仅改动了functions.php及comments.php(DUX主题,其他主题可自行选择标识显示位置)两个文件,大家在修改之前先备份下这两个文件以免误操作引起网站的崩溃。
functions.php文件修改
在主题的functions.php文件中添加如下函数:
//获取用户UA信息
function user_agent($ua){
//开始解析操作系统
$os = null;
if(preg_match(‘/Windows 95/i’,$ua) || preg_match(‘/Win95/’,$ua)){
$os=”Windows 95″;}
elseif(preg_match(‘/Windows NT 5.0/i’,$ua) || preg_match(‘/Windows 2000/i’, $ua)){
$os=”Windows 2000″;}
elseif(preg_match(‘/Win 9x 4.90/i’,$ua) || preg_match(‘/Windows ME/i’, $ua)){
$os=”Windows ME”;}
elseif(preg_match(‘/Windows.98/i’,$ua) || preg_match(‘/Win98/i’, $ua)){
$os = “Windows 98″;}
elseif(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 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(‘/Windows NT 5.2/i’,$ua)){
$os=”Windows Server 2003″;}
elseif(preg_match(‘/Mac_PowerPC/i’,$ua)){
$os=”Mac OS”;}
elseif(preg_match(‘/Windows Phone/i’,$ua)){
$os=”Windows Phone7″;}
elseif (preg_match(‘/Windows NT 6.2/i’, $ua)){
$os=”Windows 8″;}
elseif(preg_match(‘/Windows NT 4.0/i’,$ua) || preg_match(‘/WinNT4.0/i’,$ua)){
$os=”Windows NT 4.0″;}
elseif(preg_match(‘/Windows NT/i’,$ua) || preg_match(‘/WinNT/i’,$ua)){
$os=”Windows NT”;}
elseif(preg_match(‘/Windows CE/i’,$ua)){
$os=”Windows CE”;}
elseif(preg_match(‘/ipad/i’,$ua)){
$os=”iPad”;}
elseif(preg_match(‘/Touch/i’,$ua)){
$os=”Touchw”;}
elseif(preg_match(‘/Symbian/i’,$ua) || preg_match(‘/SymbOS/i’,$ua)){
$os=”Symbian OS”;}
elseif (preg_match(‘/iPhone/i’, $ua)) {
$os=”iPhone”;}
elseif(preg_match(‘/PalmOS/i’,$ua)){
$os=”Palm OS”;}
elseif(preg_match(‘/QtEmbedded/i’,$ua)){
$os=”Qtopia”;}
elseif(preg_match(‘/Ubuntu/i’,$ua)){
$os=”Ubuntu Linux”;}
elseif(preg_match(‘/Gentoo/i’,$ua)){
$os=”Gentoo Linux”;}
elseif(preg_match(‘/Fedora/i’,$ua)){
$os=”Fedora Linux”;}
elseif(preg_match(‘/FreeBSD/i’,$ua)){
$os=”FreeBSD”;}
elseif(preg_match(‘/NetBSD/i’,$ua)){
$os=”NetBSD”;}
elseif(preg_match(‘/OpenBSD/i’,$ua)){
$os=”OpenBSD”;}
elseif(preg_match(‘/SunOS/i’,$ua)){
$os=”SunOS”;}
elseif(preg_match(‘/Linux/i’,$ua)){
$os=”Linux”;}
elseif(preg_match(‘/Mac OS X/i’,$ua)){
$os=”Mac OS X”;}
elseif(preg_match(‘/Macintosh/i’,$ua)){
$os=”Mac OS”;}
elseif(preg_match(‘/Unix/i’,$ua)){
$os=”Unix”;}
elseif(preg_match(‘#Nokia([a-zA-Z0-9.]+)#i’,$ua,$matches)){
$os=”Nokia”.$matches[1];}
elseif(preg_match(‘/Mac OS X/i’,$ua)){
$os=”Mac OS X”;}
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(‘#Safari/([a-zA-Z0-9.]+)#i’,$ua,$matches)){
$browser=’Safari ‘.$matches[1];}
elseif(preg_match(‘#opera mini#i’, $ua)) {
$browser=’Opera Mini ‘.$matches[1];}
elseif(preg_match(‘#Opera.([a-zA-Z0-9.]+)#i’,$ua,$matches)){
$browser=’Opera ‘.$matches[1];}
elseif(preg_match(‘#(j2me|midp)#i’, $ua)) {
$browser=”J2ME/MIDP Browser”;}
elseif(preg_match(‘/GreenBrowser/i’, $ua)){
$browser=’GreenBrowser’;}
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(‘#MSIE ([a-zA-Z0-9.]+)#i’,$ua,$matches)){
$browser=’Internet Explorer ‘.$matches[1];}
elseif(preg_match(‘#avantbrowser.com#i’,$ua)){
$browser=’Avant Browser’;}
elseif(preg_match(‘#PHP#’, $ua, $matches)){
$browser=’PHP’;}
elseif(preg_match(‘#danger hiptop#i’,$ua,$matches)){
$browser=’Danger HipTop’;}
elseif(preg_match(‘#Shiira[/]([a-zA-Z0-9.]+)#i’,$ua,$matches)){
$browser=’Shiira ‘.$matches[1];}
elseif(preg_match(‘#Dillo[ /]([a-zA-Z0-9.]+)#i’,$ua,$matches)){
$browser=’Dillo ‘.$matches[1];}
elseif(preg_match(‘#Epiphany/([a-zA-Z0-9.]+)#i’,$ua,$matches)){
$browser=’Epiphany ‘.$matches[1];}
elseif(preg_match(‘#UP.Browser/([a-zA-Z0-9.]+)#i’,$ua,$matches)){
$browser=’Openwave UP.Browser ‘.$matches[1];}
elseif(preg_match(‘#DoCoMo/([a-zA-Z0-9.]+)#i’,$ua,$matches)){
$browser=’DoCoMo ‘.$matches[1];}
elseif(preg_match(‘#(Firefox|Phoenix|Firebird|BonEcho|GranParadiso|Minefield|Iceweasel)/([a-zA-Z0-9.]+)#i’,$ua,$matches)){
$browser=’Firefox ‘.$matches[2];}
elseif(preg_match(‘#(SeaMonkey)/([a-zA-Z0-9.]+)#i’,$ua,$matches)){
$browser=’Mozilla SeaMonkey ‘.$matches[2];}
elseif(preg_match(‘#Kazehakase/([a-zA-Z0-9.]+)#i’,$ua,$matches)){
$browser=’Kazehakase ‘.$matches[1];}
else{$browser=’未知浏览器’;
}
return $os.” | “.$browser;
}
部分主题提供给用户编辑的文件可能不是这个,具体情况大家可以咨询下主题开发者。
mo_comments_list.php文件修改
在你主题中相要添加这些标识的位置输出以下代码即可:
对于我目前使用的RIPRO主题来说是将代码添加到了comments.php中,大部分主题可能需要添加到comments.php这个文件中去,具体添加位置大家可自行选择或者咨询下主题开发者。
当然,如果你不喜欢代码版,或者代码版的操作起来有困难可以尝试使用WP-UserAgent这款插件,这款插件操作选项很多并且支持以图标的形式显示标识,但是对于这种功能性的插件,个人还是建议能少装一个是一个,毕竟多多少少会对网站速度有所影响。
与WP-UserAgent插件功能相似的还有 Comment Info Detector 和 Show UserAgent,不过这两款插件还可以显示评论者的国籍信息。推荐大家使用WP-UserAgent,毕竟大部分访客来自China!
猜你喜欢
-
如何分析网站SEO数据确定优化方向
2021-04-24 -
WordPress不用插件使用七牛云存储加速网站
2021-04-25 -
phpstorm中文汉化破解版_集成多种插件的php开发
2021-04-25 -
WordPress全新爱导航网址网站展现主题风格网站模板响应式移动端
2021-04-22 -
wp_get_attachment_image_src()函数
2021-04-26 -
俄罗斯大神WIN10 64位超级精简版1.9G
2021-04-25 -
WordPress如何调用全站、同分类随机文章
2021-04-25 -
WordPress主题分类、文章、页面、文章类型等模版继承规则和自定义方法。
2021-04-25 -
可以激活400年的Windows10政府版
2021-04-25 -
Ripro主题美化-新年/高考/节日倒计时代码(小工具)
2021-04-24
-
update_comment_meta()函数
2021-04-26 -
RiPro主题美化-添加文章开启关闭侧边栏功能
2021-04-25 -
最新WordPress安装详细教程,还在问wordpress如何安装?这篇文章解决问题
2021-04-25 -
WordPress SEO优化 如何自动为文章添加标签链接增加站点内链
2021-04-24 -
Overworld – 电子竞技游戏爱好者网站WordPress主题
2021-04-21 -
新网站如何快速获得更好的排名呢
2021-04-24 -
RIpro主题整站侧边导航条(更新到子主题)
2021-04-24 -
如何提升网站流量企业站如何做好优化计划
2021-04-24 -
WordPress 5.5 正式版发布,主要更新20个新功能
2021-04-21 -
网站优化的技巧有哪些
2021-04-24
猜你在找
常见问题FAQ
- 免费下载或者VIP会员专享资源能否直接商用?
- 本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。
- 提示下载完但解压或打开不了?
- 找不到素材资源介绍文章里的示例图片?
- 大资源
- 2021-04-25Hi,初次和大家见面了,请多关照!
最后编辑:2021-04-25

