当前位置:首页 > 文章 > 帝国CMS > 正文内容

帝国cms电脑网站跳转到手机动态网站和手机静态网站的方法

3年前 (2022-10-21)帝国CMS11088
本文讲解一下帝国cms电脑网站跳转到手机动态网站和手机静态网站的方法。

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

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

添加上面代码后,pc网站就可以跳转到手机端的对应网页了。
注意:使用上面代码时,把代码中的域名改成你自己的域名就可以了。
————————————————
版权声明:本文为CSDN博主「cjava2012」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://oss.blueboss.cn/blueboss/zb_users/upload/2022/10c/21/cb124209512p166

扫描二维码推送至手机访问。

版权声明:本文由蓝博发布,如需转载请注明出处。

本文链接:https://blueboss.cn/p/250.shtml

“帝国cms电脑网站跳转到手机动态网站和手机静态网站的方法” 的相关文章

帝国CMS模板用灵动标签调用同级栏目导航并且当判断显示当前栏目高亮

帝国CMS模板用灵动标签调用同级栏目导航并且当判断显示当前栏目高亮

帝国cms模板里面怎么用灵动标签调用同级的栏目导航呢?同时判断显示当前栏目导航高亮! 调用代码:(注意:hover为判断当前高亮css样式) [e:loop={"select classname,classpath,classid from phome_enewsclass where bclas...

帝国CMS模板中不同会员组显示不同内容

帝国CMS模板中不同会员组显示不同内容

帝国cms模板里面不同会员组显示不同内容怎么实现? 具体调用代码如下: <?php  if(getcvar('mlgroupid')<1)  {  ?>  //游客看到的内容  <?php  }  elseif(getcvar('mlgroupid')==1)  {  ?&...

帝国CMS内容页调用指定ID的文章可以指定多篇

帝国CMS内容页调用指定ID的文章可以指定多篇

帝国CMS内容页中调用多篇指定id文章的方法,下面一起来学习学习吧: 大概的思路是: 新建1个产品文章字段,这样的话,每个产品里面都可以填写不同的产品id,然后在模板里面调用出来即可。 下面附上内容页模板里面调用多篇指定文章id的php代码: <?php $sql='id in ('.$na...

帝国CMS404页面优化有什么作用

帝国CMS404页面优化有什么作用

我们应该正确理解什么是帝国cms 404页面。404页面是当页面不存在时被提示的页面。本页面可根据网站管理员的个人喜好随意显示。 用户浏览网站时遇到的错误页面地址、输入错误或帝国cms内容发布后未生成内容页面的原因并不多。然而,这种情况很少见。大多数情况下,搜索引擎可能会包含某个页面。但是,由于不小...

帝国CMS怎么调用自定义分类怎么实现

帝国CMS怎么调用自定义分类怎么实现

帝国CMS调用自定义分类的方法:   具体标签如下: [e:loop={'select id,path,title from [!db.pre!]enewspage where classid=1 order by id',20,24,0}] <?php $pageurl=$public_r...

帝国cms模板哪些垃圾代码可以清理掉?

帝国cms模板哪些垃圾代码可以清理掉?

帝国cms模板中哪些垃圾代码可以清理掉? 清理无用的垃圾代码和不必要的内容是模板制作过程中非常重要的环境环节。让我们详细分析一下,看看在制作过程中是否还有一些问题。 总结无用可分为:重复的CSS定义,太多的空格字符,CSS默认属性,无用和太多的注释语句,空代码标签。 1.空格字符太多 空格字符是在编...