首页 > CMS建站 > PhpCMS > 正文

phpcms自动跳转到wap手机站的实现方法

2020-07-03 13:06:25
字体:
来源:转载
供稿:网友
这篇文章主要为大家详细介绍了phpcms自动跳转到wap手机站的实现方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下,有需要的朋友可以收藏方便以后借鉴。

前面361源码已经给大家讲过《DedeCMS移动端访问pc网址自动跳转代码》和《PC电脑访问移动端网页网站自动跳转到对应PC网站代码》的方法,相信不少朋友在处理织梦内核程序的站点的时候,都不会有什么太大的问题。那么phpcms V9如何实现自动跳转到wap手机站的呢?下面361源码给大家介绍个简单的方法,但是稍有局限性,不能实现对应页面跳转。方法如下:

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

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

<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.cuoxin.com";}else if(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}</script>

注意

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

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

首页跳转

分析:

PC电脑版首页:www.cuoxin.com

WAP手机版首页:m.cuoxin.com

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

实现代码

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

<meta http-equiv="mobile-agent" content="format=xhtml;url=http://m.cuoxin.com/"><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.cuoxin.com/";}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.cuoxin.com/"><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.cuoxin.com/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.cuoxin.com/"><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.cuoxin.com/index.php?&a=show&catid={$catid}&typeid=<?php echo $b; ?>&id={$id}";}else if(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}</script>

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

其实这个方法比较局限,如果你有更好方法可以联系361源码哦,把更好的方法分享给大家。


以上就是phpcms自动跳转到wap手机站的实现方法的全部内容,希望对大家的学习和解决疑问有所帮助,也希望大家多多支持错新网。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表