欢迎光临
我们一直在努力

织梦跳转适配代码

新起点博客先提醒大家用前记得先测试,有的标签不一定适合你!尤其是移动端标签!!

PC站首页模板:

首页

<meta http-equiv="mobile-agent" content="format=xhtml;url={dede:global.cfg_mobileurl/}/">
<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 = "{dede:global.cfg_mobileurl/}/";
                    } else if (/iPad/i.test(navigator.userAgent)) {} else {}
                } catch (e) {}
            }
        }
    }
</script>

栏目页

<meta http-equiv="mobile-agent" content="format=xhtml;url={dede:global.cfg_mobileurl/}/list.php?tid={dede:field.id/}">
<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 = "{dede:global.cfg_mobileurl/}/list.php?tid={dede:field.id/}";
                    } else if (/iPad/i.test(navigator.userAgent)) {} else {}
                } catch (e) {}
            }
        }
    }
</script>

文章页

<meta http-equiv="mobile-agent" content="format=xhtml;url={dede:global.cfg_basehost/}view.php?aid={dede:field.id/}">
<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 = "{dede:global.cfg_mobileurl/}/view.php?aid={dede:field.id/}";
                    } else if (/iPad/i.test(navigator.userAgent)) {} else {}
                } catch (e) {}
            }
        }
    }
</script>

另外,还可使用<link>标签以便于百度更好地发现PC站和移动站的移动适配关系,在模板的<head></head>标签内加入如下代码:

PC站首页模板:

<link rel="alternate" media="only screen and (max-width: 640px)" href="{dede:global.cfg_mobileurl/}/" >

PC站栏目页模板:

<link rel="alternate" media="only screen and (max-width: 640px)" href="{dede:global.cfg_mobileurl/}/list.php?tid={dede:field.id/}" >

PC站文章页模板:

<link rel="alternate" media="only screen and (max-width: 640px)" href="{dede:global.cfg_mobileurl/}/view.php?aid={dede:field.id/}" >

移动站

首页模板:

<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="canonical" href="{dede:global.cfg_basehost/}/ " />

栏目页模板:

<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="canonical" href="{dede:global.cfg_basehost/}{dede:type typeid='0' row=1}[field:typelink /]{/dede:type}" />

 

内容页模板:

<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="canonical" href="{dede:global.cfg_basehost/}{dede:field.id runphp='yes'}$id=@me;@me='';$url=GetOneArchive($id);@me=$url['arcurl'];{/dede:field.id}" />

 

赞(0) 打赏
未经允许不得转载:新起点博客 » 织梦跳转适配代码
分享到: 更多 (0)

评论 抢沙发

评论前必须登录!

 

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续给力更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏