便宜vps推荐!

帝国cms:手机访问电脑pc站时自动跳转到手机站的方法

时间:|浏览:| 评论 ()

本文讲解一下帝国cms电脑网站跳转到手机动态网站和手机静态网站的方法。

方法一:帝国pc站跳转到手机静态站

1、假设我们有帝国cms 电脑网站www.lazybirdfly.com,手机网站m.lazybirdfly.com ,手机网站使用帝国cms的多访问端功能制作,如果不了解帝国cms多访问端制作手机网站的方法,请参考:http://www.lazybirdfly.com/a/ecms/658.html
现在电脑端和手机端都是生成静态网站,除了域名不同,静态连接地址都是相同的,例如:
www.lazybirdfly.com/china/1.html对应 m.lazybirdfly.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.lazybirdfly.com/";}}}
catch(err)
{
}</script>
<meta name="mobile-agent" content="format=xhtml;url=http://m.lazybirdfly.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.lazybirdfly.com<?=sys_ReturnBqClassUrl($class_r[$GLOBALS[navclassid]]);?>";}}}
catch(err)
{
}</script>
<meta name="mobile-agent" content="format=xhtml;url=http://m.lazybirdfly.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.lazybirdfly.com[!--titleurl--]";}}}
catch(err)
{
}</script>
<meta name="mobile-agent" content="format=xhtml;url=http://m.lazybirdfly.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.lazybirdfly.com/";}}}
catch(err)
{
}</script>
<meta name="mobile-agent" content="format=xhtml;url=http://m.lazybirdfly.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.lazybirdfly.com/e/action/ListInfo/?classid=[!--self.classid--]";}}}
catch(err)
{
}</script>
<meta name="mobile-agent" content="format=xhtml;url=http://m.lazybirdfly.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.lazybirdfly.com/e/action/ShowInfo.php?classid=[!--classid--]&id=[!--id--]";}}}
catch(err)
{
}</script>
<meta name="mobile-agent" content="format=xhtml;url=http://m.lazybirdfly.com/e/action/ShowInfo.php?classid=[!--classid--]&id=[!--id--]">

添加上面代码后,pc网站就可以跳转到手机端的对应网页了。注意:使用上面代码时,把代码中的域名改成你自己的域名就可以了。
声明:VPSNO仅为VPS服务器信息分享,任何IDC都有倒闭和跑路可能,本站无法作任何保障,请网友购买前自行斟酌,衡量评估风险,自负责任。数据勤备份是最佳选择。本文由VPSNO网站发布,转载请保留链接:《帝国cms:手机访问电脑pc站时自动跳转到手机站的方法》站长联系QQ:22⑧2六8⑦肆8,邮箱为QQ邮箱。
网友评价
评论列表
共有 条评论

精选便宜VPS - VPS排行

  • No.1 最便宜的大厂云服务器
    UCloud云服务器

    UCloud云服务器

    UCloud(优刻得)是国内最大的中立公有云服务商,全球包含香港、台湾共25个数据中心,52元/年起

  • No.2 国内用户最多的云服务器
    阿里云服务器

    阿里云服务器

    阿里云是国内云服务器第一梯队头部商家,目前国内用户选择最多的云服务器商。

  • No.3 号称“良心云”的云服务器
    腾讯云服务器

    腾讯云服务器

    和阿里云规模相当的国内云服务器商,套路少,给100%CPU资源,拥有更好的性价比。

  • 热度飙升最快的国外VPS
    RackNerd

    RackNerd

    RackNerd是2019年成立的主机商,以提供便宜VPS、大带宽VPS闻名,近年来在国内用户中知名度颇高。

  • 最受国人欢迎的国外VPS
    bandwagonhost搬瓦工

    bandwagonhost搬瓦工

    搬瓦工VPS可能是中国用户数量最多的服务商,专为大陆用户定制了大量功能,线路有特别优化,快而稳定。

  • 实力雄厚的老牌国外VPS
    vultr

    vultr

    Vultr是成立于2014年的老牌IDC,全球16个机房,硬件配置极高,新用户注册赠送100美元余额。