前面361源碼已經給大家講過《DedeCMS移動端訪問pc網址自動跳轉代碼》和《PC電腦訪問移動端網頁網站自動跳轉到對應PC網站代碼》的方法,相信不少朋友在處理織夢內核程序的站點的時候,都不會有什么太大的問題。那么phpcms V9如何實現自動跳轉到wap手機站的呢?下面361源碼給大家介紹個簡單的方法,但是稍有局限性,不能實現對應頁面跳轉。方法如下:
只需在模板的<head></head>之間添加如下代碼即可
<meta http-equiv="mobile-agent" content="format=xhtml;url=http://m.vevb.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.vevb.com";}else if(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}</script>
注意:
將本文中的“http://m.vevb.com/”替換為你的手機站域名,一定要以“http://”開頭
這樣就能實現移動設備訪問站點的時候跳轉到手機站點了,唯一的缺憾是不能實現對應跳轉。當然,如果在特定的條件下phpcms V9也是能夠實現對應跳轉的,條件就是:只有當catid與typeid相減的結果相同時才可以用。
首頁跳轉:
分析:
PC電腦版首頁:www.companysz.com
WAP手機版首頁:m.vevb.com
通過JS代碼實現當打開www.companysz.com的時候跳轉到m.vevb.com
實現代碼:
在<head></head>之間添加如下代碼即可:
<meta http-equiv="mobile-agent" content="format=xhtml;url=http://m.vevb.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.vevb.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.vevb.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.vevb.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.vevb.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.vevb.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.vevb.com替換為您移動端的域名哦!!
其實這個方法比較局限,如果你有更好方法可以聯系361源碼哦,把更好的方法分享給大家。
新聞熱點
疑難解答