帝國cms電腦pc站url跳轉到手機站url的方式
2024-08-28 12:25:14
供稿:網友
本文講解一下帝國cms電腦網站跳轉到手機動態網站和手機靜態網站的方法。
方法一:帝國pc站跳轉到手機靜態站
1、假設我們有帝國cms 電腦網站www.cmsyuanma.com,手機網站m.cmsyuanma.com ,手機網站使用帝國cms的多訪問端功能制作,如果不了解帝國cms多訪問端制作手機網站的方法,請參考:http://www.cmsyuanma.com/a/ecms/658.html
現在電腦端和手機端都是生成靜態網站,除了域名不同,靜態連接地址都是相同的,例如:
www.cmsyuanma.com/china/1.html對應 m.cmsyuanma.com/china/1.html
2、接下來要給電腦網站的首頁、列表頁、內容頁的模板添加跳轉代碼,方法如下:
js是瀏覽器跳轉,meta是告訴搜索引擎移動頁面的地址。
(1)首頁模板需添加下面代碼
<script type="text/javascript">
try {var urlhash = window.location.hash;if (!urlhash.match("fromapp"))
{if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i)))
{window.location="http://m.cmsyuanma.com/";}}}
catch(err)
{
}</script>
<meta name="mobile-agent" content="format=xhtml;url=http://m.cmsyuanma.com/">
(2)封面頁和列表頁添加下面代碼
<script type="text/javascript">
try {var urlhash = window.location.hash;if (!urlhash.match("fromapp"))
{if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i)))
{window.location="http://m.cmsyuanma.com<?=sys_ReturnBqClassUrl($class_r[$GLOBALS[navclassid]]);?>";}}}
catch(err)
{
}</script>
<meta name="mobile-agent" content="format=xhtml;url=http://m.cmsyuanma.com<?=sys_ReturnBqClassUrl($class_r[$GLOBALS[navclassid]]);?>">
(3)內容頁添加下面代碼
<script type="text/javascript">
try {var urlhash = window.location.hash;if (!urlhash.match("fromapp"))
{if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i)))
{window.location="http://m.cmsyuanma.com[!--titleurl--]";}}}
catch(err)
{
}</script>
<meta name="mobile-agent" content="format=xhtml;url=http://m.cmsyuanma.com[!--titleurl--]">
添加完上面代碼后,帝國cms的電腦網站的每個頁面都可以跳轉到手機靜態網站了。
但手機靜態站是有缺點的,每次我們更新電腦端文章,都要去手機端后臺重新生成一下html,比較麻煩,所以我們可以把手機站設置成動態訪問,接下來就講解一下電腦端跳轉手機動態站的方法。
方法二:帝國cms電腦網站跳轉到手機動態站的方法
1、首先在電腦端的多訪問端設置,把手機端設置成強制動態頁面模式。這樣手機站就是動態了,不用每次都去生成html 。
2、接下來就是給電腦端模板的首頁、列表頁、內容頁添加相依跳轉代碼,和方法一類似。
js是瀏覽器跳轉,meta是告訴搜索引擎移動頁面的地址。
(1)首頁模板需添加下面代碼
<script type="text/javascript">
try {var urlhash = window.location.hash;if (!urlhash.match("fromapp"))
{if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i)))
{window.location="http://m.cmsyuanma.com/";}}}
catch(err)
{
}</script>
<meta name="mobile-agent" content="format=xhtml;url=http://m.cmsyuanma.com/">
(2)封面頁和列表頁添加下面代碼
<script type="text/javascript">
try {var urlhash = window.location.hash;if (!urlhash.match("fromapp"))
{if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i)))
{window.location="http://m.cmsyuanma.com/e/action/ListInfo/?classid=[!--self.classid--]";}}}
catch(err)
{
}</script>
<meta name="mobile-agent" content="format=xhtml;url=http://m.cmsyuanma.com/e/action/ListInfo/?classid=[!--self.classid--]">
(3)內容頁添加下面代碼
<script type="text/javascript">
try {var urlhash = window.location.hash;if (!urlhash.match("fromapp"))
{if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i)))
{window.location="http://m.cmsyuanma.com/e/action/ShowInfo.php?classid=[!--classid--]&id=[!--id--]";}}}
catch(err)
{
}</script>
<meta name="mobile-agent" content="format=xhtml;url=http://m.cmsyuanma.com/e/action/ShowInfo.php?classid=[!--classid--]&id=[!--id--]">
添加上面代碼后,pc網站就可以跳轉到手機端的對應網頁了。
注意:使用上面代碼時,把代碼中的域名改成你自己的域名就可以了。