首页 > 问题解答 > 正文

phpcms各模板页面自动跳转到wap手机站的方法
2022-04-05 17:55:52   来源:   评论:0 点击:

phpcms V9如何实现自动跳转到wap手机站的呢?下面给大家介绍个简单的方法,但是稍有局限性,不能实现对应页面跳转。方法如下:只需在模板

phpcms V9如何实现自动跳转到wap手机站的呢?下面给大家介绍个简单的方法,但是稍有局限性,不能实现对应页面跳转。方法如下:

只需在模板的<head></head>之间添加如下代码即可

<meta http-equiv="mobile-agent" content="format=xhtml;url=http://m.phpcms.shop/">

<script type="text/javascript">if(window.location.toString().indexOf('pref=padindex') != -1){}else{if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){if(window.location.href.indexOf("?mobile")<0){try{if(/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){window.location.href=http://m.phpcms.shop;}else if(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}</script>

注意

将本文中的“http://m.phpcms.shop/”替换为你的手机站域名,一定要以“http://”开头

这样就能实现移动设备访问站点的时候跳转到手机站点了,唯一的缺憾是不能实现对应跳转。当然,如果在特定的条件下phpcms V9也是能够实现对应跳转的,条件就是:只有当catid与typeid相减的结果相同时才可以用。

首页跳转

分析:

PC电脑版首页:www.phpcms.shop

WAP手机版首页:m.phpcms.shop

通过JS代码实现当打开www.phpcms.shop的时候跳转到m.phpcms.shop

实现代码

在<head></head>之间添加如下代码即可:

<meta http-equiv="mobile-agent" content="format=xhtml;url=http://m.phpcms.shop/"><script type="text/javascript">if(window.location.toString().indexOf('pref=padindex') != -1){}else{if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){if(window.location.href.indexOf("?mobile")<0){try{if(/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){window.location.href="http://m.phpcms.shop/";}else if(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}</script>

栏目页跳转

分析:以前3个栏目为例分析

PC电脑版栏目ID:新闻动态--catid=101 行业动态--catid=102 各类问答--catid=103

WAP手机版栏目ID:新闻动态--typeid=1 行业动态--typeid=2 各类问答--typeid=3

通过观察WAP手机版栏目页链接CMS集中营站长发现只需要调出WAP手机版的typeid即可,可是用{$typeid}调不出来,{$catid}虽然可以调出数据但是不是想要的,再观察发现我的catid-100=typeid,这样通过php代码得出了typeid,就可以实现了栏目页的跳转

实现代码:

在<head></head>之间添加如下代码即可:

<?php $a = $catid; ?><?php $b = $a-100; ?><meta http-equiv="mobile-agent" content="format=xhtml;url=http://m.phpcms.shop/"><script type="text/javascript">if(window.location.toString().indexOf('pref=padindex') != -1){}else{if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){if(window.location.href.indexOf("?mobile")<0){try{if(/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){window.location.href="http://m.phpcms.shop/index.php?&a=lists&typeid=<?php echo $b; ?>";}else if(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}</script>

内容页跳转

分析:

在文章页的跳转代码中catid可以用{$catid}调用,id可以用{$id}调用,typeid咱们在栏目页跳转时已经分析过了可以通过php实现

实现代码:

在<head></head>之间添加如下代码即可:

<?php $a = $catid; ?><?php $b = $a-100; ?><meta http-equiv="mobile-agent" content="format=xhtml;url=http://m.phpcms.shop/"><script type="text/javascript">if(window.location.toString().indexOf('pref=padindex') != -1){}else{if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){if(window.location.href.indexOf("?mobile")<0){try{if(/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){window.location.href="http://m.phpcms.shop/index.php?&a=show&catid={$catid}&typeid=<?php echo $b; ?>&id={$id}";}else if(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}</script>

温馨提示:记得将m.phpcms.shop替换为您移动端的域名哦!!

其实这个方法比较局限,如果你有更好方法,把更好的方法分享给大家。

 以上就是phpcms自动跳转到wap手机站的实现方法的全部内容,希望对大家的学习和解决疑问有所帮助,也希望大家多多支持phpcms共享学习网。

相关热词搜索:

上一篇:PHPCMS v9管理后台登录去除验证码的方法
下一篇:phpcms前台用户出现“请一个小时后登录”问题解决

分享到: 收藏
评论排行
扫一扫关注公众号
全国统一服务热线 0731-84037726
座机:0731-84037726
微信扫一扫 关注我们
客服