dedecms织梦移动版伪静态 - 实现与PC电脑版静态地址url一致教程+伪静态规则

2018-04-28dedecms开发
784

移动版伪静态效果




修改以下4个文件
\m\index.php
\m\list.php
\m\view.php
\include\arc.listview.class.php
 
电脑版静态生成这里就不多说了,移动版伪静态操作教程如下:
 
1.移动版域名 m.123.com 解析并指向绑定目录到网站目录的m文件夹
 
 
2.后台-系统配置 添加变量 (为了使用绝对路径,使用电脑版的文章图片,为了移动版模板css、js、images使用绝对路径)
 
变量名称:cfg_mobile
变量类型:文本
参数说明:手机版网址
变量值:http://m.123.com
所属组:站点设置
 
变量名称:cfg_rewritem
变量类型:布尔(Y/N)
参数说明:手机版伪静态
变量值:Y
所属组:站点设置



栏目列表【文件保存目录】可以是以下形式




3.\m\index.php 修改成永远是动态,不生成index.html
把里面的
 
$row[‘showmod‘] = isset($row[‘showmod‘])? $row[‘showmod‘] : 0;
if ($row[‘showmod‘] == 1)
{
    $pv->SaveToHtml(dirname(__FILE__).‘/index.html‘);
    include(dirname(__FILE__).‘/index.html‘);
    exit();
} else { 
    $pv->Display();
    exit();
}
改成
 
$pv->SetTemplet($cfg_basedir . $cfg_templets_dir . "/" . $row[‘templet‘]);
$pv->Display();
exit();
 
4.\m\list.php 增加伪静态判断
把里面的
 
$tid = (isset($tid) && is_numeric($tid) ? $tid : 0);
改成
 
if($cfg_rewritem == ‘Y‘)
{
    $typedir = parse_url($tid, PHP_URL_PATH);
    $PageNo = stripos(GetCurUrl(), ‘.html‘) ? intval(str_replace(‘.html‘, ‘‘, end(explode("_", GetCurUrl())))) : 1;
    $tinfos = $dsql->GetOne("SELECT * FROM `wmd_arctype` WHERE typedir=‘/$typedir‘ or typedir=‘{cmspath}/$typedir‘");

    if(is_array($tinfos))
    {
        $tid = $tinfos[‘id‘];
        $typeid = GetSonIds($tid);
        $row = $dsql->GetOne("Select count(id) as total From `wmd_archives` where typeid in({$typeid})");
        $TotalResult = is_array($row) ? $row[‘total‘] : 0;
    }
    else
    {
        $tid = 0;
    }
}
else
{
    $tid = (isset($tid) && is_numeric($tid) ? $tid : 0);
}
5.\m\view.php 增加伪静态判断

 
$t1 = ExecTime();
下面加入
 
if($cfg_rewritem == ‘Y‘)
{
    $aid = stripos(GetCurUrl(), ‘.html‘) ? intval(str_replace(‘.html‘, ‘‘, end(explode("/", GetCurUrl())))) : 0;
}
 
6.\include\arc.listview.class.php 增加移动版伪静态分页功能,找到
 
global $cfg_rewrite;
改成
 
global $cfg_rewrite,$cfg_rewritem;
继续找到
 
$geturl = "tid=".$this->TypeID."&TotalResult=".$this->TotalResult."&";
$purl .= ‘?‘.$geturl;
改成
 
if($cfg_rewritem == ‘Y‘)
{
    $purl = "";
}
else
{
    $geturl = "tid=".$this->TypeID."&TotalResult=".$this->TotalResult."&";
    $purl .= ‘?‘.$geturl;
}
继续找到下面的
 
return $plist;
在它的上面加入
 
if($cfg_rewritem == ‘Y‘)
{
    $plist = preg_replace("/PageNo=(\d+)/i",‘list_‘.$this->TypeID.‘_\\1.html‘,$plist);
}
7.移动版模板中使用标签有
 
{wmd:global.cfg_mobile/}    http://m.123.com
 
[field:global.cfg_basehost/][field:litpic/]    图片用主站的,如:http://www.123.com/uploads/allimg/170513/20493W4S-0.jpg
 
{wmd:field.body/}
 
改成
 
{wmd:field.body runphp=yes}
global $cfg_basehost;
$str = @me;
$search = ‘/(<img.*?)width=(["\‘])?.*?(?(2)\2|\s)([^>]+>)/is‘;//过滤img里的width
$search1 = ‘/(<img.*?)height=(["\‘])?.*?(?(2)\2|\s)([^>]+>)/is‘;//过滤img里的height
$search2 = ‘#(<img.*?style=".*?)width:\d+px;([^"]*?.*?>)#i‘;//过滤img里style的width
$search3 = ‘#(<img.*?style=".*?)height:\d+px;([^"]*?.*?>)#i‘;//过滤img里style的height
$content = preg_replace($search,‘$1$3‘,$str);
$content = preg_replace($search1,‘$1$3‘,$content);
$content = preg_replace($search2,‘$1$2‘,$content);
$content = preg_replace($search3,‘$1$2‘,$content);
@me = $content;
@me = str_replace(‘/uploads/allimg/‘, $cfg_basehost.‘/uploads/allimg/‘, $content);//手机版图片使用绝对路径
{/wmd:field.body}
 
其他标签跟电脑版一样
 
8.移动版伪静态规则 apache
 
.htaccess  放到m文件夹下

注意栏目【列表命名规则】要对应伪静态栏目分页规则和\include\arc.listview.class.php里面的分页规则。



#dedecms移动版伪静态
RewriteEngine On
RewriteBase /

#移动版列表栏目
RewriteRule ^(.*)/$ /list.php?tid=$1
#移动版列表栏目分页
RewriteRule ^(.*)/list_([0-9]+)_([0-9]+)\.html$ /list.php?tid=$1&PageNo=$2
#移动版文章页伪静态规则
RewriteRule ^(.*)/([0-9]+)\.html$ /view.php?aid=$1

9.电脑版跳转到移动版代码
 
1)首页
 
<meta http-equiv="mobile-agent" content="format=xhtml;url={wmd:global.cfg_mobile/}">
<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="{wmd:global.cfg_mobile/}";}else if(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}</script>
 
2)列表
 
<meta http-equiv="mobile-agent" content="format=xhtml;url={wmd:global.cfg_mobileurl/}{wmd:type}[field:typeurl/]{/wmd:type}">
<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="{wmd:global.cfg_mobileurl/}{wmd:type}[field:typeurl/]{/wmd:type}";}else if(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}</script>
 
3)内容
 
<meta http-equiv="mobile-agent" content="format=xhtml;url={wmd:global.cfg_mobile/}{wmd:field.id runphp=yes}$result=GetOneArchive(@me);@me=$result[‘arcurl‘];{/wmd: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="{wmd:global.cfg_mobile/}{wmd:field.id runphp=yes}$result=GetOneArchive(@me);@me=$result[‘arcurl‘];{/wmd:field.id}";}else if(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}</script>
完成
The End

相关推荐

织梦cms批量删除所有无效TAGS的办法
使用过DedeCMS的站长应当都遇到过这样的问题,在我们删掉一些文章内容后,tags标识中就慢慢拥有许多失效的标识存有,这种TAGS标识并不会跟随大家删掉文章内容一起删掉,如果是受欢迎的词还行,有很多文章内容都是有,如果是小众词,便会发生在TAGS目录有词,...
2023-08-17 dedecms开发
181

怎么修改织梦DEDECMS源码tags标签字数限制
修改织梦DEDECMS中TAG标签字数长度限制的方法共两个步骤,分别是对数据库字数和提交文件的字数进行修改。 一、我们通过织梦DEDECMS后台程序中的系统设置栏目下的SQL命令行工具,来修改数据库中表wmd_tagindex 和wmd_taglist的tag字段属性,将TAG字段属性中...
2023-02-16 dedecms开发
196

织梦dedecms列表页实现第一页与其他页调用不同模板的办法
我们想让dedecms织梦第一页与其他第二页、第三页、、、后面的页调用的不同模板,这个要怎么实现呢? 第一步 修改核心文件 打开 /include/arc.listview.class.php 找到,大概在第330行 $this-ParseDMFields($this-PageNo,1); 在它的上面加入: $tempfile = $GL...
2022-11-19 dedecms开发
195

织梦dedecms调用当前栏目文章数的方法
这篇文章给大家分享的是有关织梦dedecms调用当前栏目文章数的方法的内容。小编觉得挺实用的,因此分享给大家做个参考。一起跟随小编过来看看吧。 做模板时,经常需要为每个栏目加上此栏目的文章数。和大家分享下实现的方法,此方法适合5.6及5.7、5.7sp1其它...
2022-11-05 dedecms开发
186

dedecms织梦无需登录注册可下单购买的修改
dedecms织梦无需登录注册可下单购买的修改,首先找到/plus/carbuaction.php文件,找到如下代码: //确认用户登录信息if($cfg_ml-IsLogin()){ $userid = $cfg_ml-M_ID;}else{ $username = trim($username); $password = trim($password); if(empty($username)...
2022-11-02 dedecms开发
171

DEDECMS织梦复制https链接网站图片无法本地化的解决办法
现在许多网站使用了SSL技术,网站采用https链接,我们在复制https链接网站的内容,发现图片无法本地化,那么我们想要将这些图片本地化,要怎么操作呢? 第一步: 找到dede/inc/inc_archives_functions.php (注:前边红色的dede目录是您的后台目录) 定位到...
2022-06-15 dedecms开发
125