建站百科

网站建设、网站设计、网站开发、域名、主机、服务器等知识普及

PHPCMS网站适配手机4部曲

最近更新于 2020-07-24 - 跨屏互联-建站
文章导读:本文主要阐述了“PHPCMS网站适配手机4部曲”phpcms 是一款基于php+mysql开发的非常受欢迎的网站系统,它比较多的用于企业网站的开发,如果你是用phpcms搭建的网站,而此时你...,本文由跨屏互联最后更新于2020-07-24,全文共3218个字,预计阅读时长10分43秒

 phpcms 是一款基于php+mysql开发的非常受欢迎的网站系统,它比较多的用于企业网站的开发,如果你是用phpcms搭建的网站,而此时你又正愁如何让网站适配手机的话,针对于phpcms适配手机的问题,只需要完成下面4部:

第一步 添加扩展函数 找到文件并且打开  /phpcms/libs/functions/extention.func.php 添加如下代码:
//判断设备  返回bool

function is_mobile() { $user_agent = $_SERVER['HTTP_USER_AGENT']; $mobile_agents = Array("240x320","acer","acoon","acs-","abacho","ahong","airness","alcatel","amoi","android","anywhereyougo.com","applewebkit/525","applewebkit/532","asus","audio","au-mic","avantogo","becker","benq","bilbo","bird","blackberry","blazer","bleu","cdm-","compal","coolpad","danger","dbtel","dopod","elaine","eric","etouch","fly ","fly_","fly-","go.web","goodaccess","gradiente","grundig","haier","hedy","hitachi","htc","huawei","hutchison","inno","ipad","ipaq","ipod","jbrowser","kddi","kgt","kwc","lenovo","lg ","lg2","lg3","lg4","lg5","lg7","lg8","lg9","lg-","lge-","lge9","longcos","maemo","mercator","meridian","micromax","midp","mini","mitsu","mmm","mmp","mobi","mot-","moto","nec-","netfront","newgen","nexian","nf-browser","nintendo","nitro","nokia","nook","novarra","obigo","palm","panasonic","pantech","philips","phone","pg-","playstation","pocket","pt-","qc-","qtek","rover","sagem","sama","samu","sanyo","samsung","sch-","scooter","sec-","sendo","sgh-","sharp","siemens","sie-","softbank","sony","spice","sprint","spv","symbian","tablet","talkabout","tcl-","teleca","telit","tianyu","tim-","toshiba","tsm","up.browser","utec","utstar","verykool","virgin","vk-","voda","voxtel","vx","wap","wellco","wig browser","wii","windows ce","wireless","xda","xde","zte"); $is_mobile = false; foreach ($mobile_agents as $device) { if (stristr($user_agent, $device)) { $is_mobile = true; break; } } return $is_mobile; }

第二步 找到首页函数文件控制器,添加如下代码:
在$id = intval($_GET[‘id’]);后面添加

$is_mobile = is_mobile(); //bool

//如果是手持设备 跳转手机页面 伪静态网址链接,自行定义

if(!$is_mobile){ $url = APP_PATH.'content-'.$catid.'-'.$id.'-1.html'; echo "<script>location.href='".$url."'</script>"; exit; }

第三步 找到正文页函数文件控制器页面,添加如下代码:
if(!$catid || !$id) showmessage(L(‘information_does_not_exist’),’blank’);后面添加

$is_mobile = is_mobile(); //bool //如果是手持设备 跳转手机页面 if($is_mobile){ switch ($catid) { case '6': $typeid = '9'; break; case '7': $typeid = '14'; break; // 。。。。 自行添加 参考图一  default: //code break; }  $url = 'http://m.kuaping.com/index.php?a=show&catid='.$catid.'&typeid='.$typeid.'&id='.$id; echo "<script>location.href='".$url."'</script>"; exit; }

第四步:首页进行自适应调整就可以了。

<script type="text/javascript"> function uaredirect(f){try{if(document.getElementById("bdmark")!=null){return}var b=false;if(arguments[1]){var e=window.location.host;var a=window.location.href;if(isSubdomain(arguments[1],e)==1){f=f+"/#m/"+a;b=true}else{if(isSubdomain(arguments[1],e)==2){f=f+"/#m/"+a;b=true}else{f=a;b=false}}}else{b=true}if(b){var c=window.location.hash;if(!c.match("fromapp")){if((navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i))){location.replace(f)}}}}catch(d){}}function isSubdomain(c,d){this.getdomain=function(f){var e=f.indexOf("://");if(e>0){var h=f.substr(e+3)}else{var h=f}var g=/^www\./;if(g.test(h)){h=h.substr(4)}return h};if(c==d){return 1}else{var c=this.getdomain(c);var b=this.getdomain(d);if(c==b){return 1}else{c=c.replace(".","\\.");var a=new RegExp("\\."+c+"$");if(b.match(a)){return 2}else{return 0}}}};  </script> <script type="text/javascript">uaredirect("http://m.kuaping.com/");</script>

写在最后,以上就是对于“PHPCMS网站适配手机4部曲”的一些看法,欢迎指正、交流。

新闻名称:PHPCMS网站适配手机4部曲
地址分享:http://www.kuaping.com/article/show159.html

相关文章推荐
推荐模板
外贸网站kptrade模板,响应式宽屏,多语言2024
编号:default#kptrade2024
跨屏五合一响应式网站官方旗舰模板kpsvip 2024版本
编号:default#kpsite2024
简约货运物流快递公司网站模板
编号:1st#wuliu
AI生成白色简洁设计师网站模板下载
编号:1st#baisejianjie
高端旅游线路推荐旅行社官网模板
编号:part2#lvyouluxian
免责声明:本站是自助建站平台,仅提供信息存储空间服务,该信息内容的真实性及合法性由该发布者完全负责。
咨询客服

10年品牌 专注五合一网站

前台客服

技术客服

027-817-77732

133-434-77732

关注我们

关注跨屏互联公众号

回到顶部