织梦跳转适配代码

原创 新起点博客  2020-05-22 09:37 
【上云必备】上云仅?102/年

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

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}" />

 

本文地址:https://www.henenseo.com/archives/1994
关注我们:请关注一下我们的微信公众号:扫描二维码新起点博客的公众号,公众号:xinqidian129
版权声明:本文为原创文章,版权归 新起点博客 所有,欢迎分享本文,转载请保留出处!
宝塔服务器面板,一键全能部署及管理,送你3188元礼包,点我领取
【腾讯云】海外1核2G服务器低至2折,半价续费券限量免费领取!

发表评论


表情