當前位置:主頁 > 站長學院 > CMS教程 > 織夢教程 > >正文
電腦版靜態效果
移動版偽靜態效果
以下教程所修改的文件(utf8/gbk)打包下載:
修改或者覆蓋文件之前請備份以下4個文件
\m\index.php
\m\list.php
\m\view.php
\include\arc.listview.class.php
鏈接: https://pan.baidu.com/s/1i49ABe1 密碼: 2wid
電腦版靜態生成這里就不多說了,移動版偽靜態操作教程如下:
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 `siy_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 `siy_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.移動版模板中使用標簽有
{dede:global.cfg_mobile/} http://m.123.com
[field:global.cfg_basehost/][field:litpic/] 圖片用主站的,如:http://www.123.com/uploads/allimg/170513/20493W4S-0.jpg
{dede:field.body/}
改成
{dede:field.body runphp=yes}
global $cfg_basehost;
$str = @me;
$search = '/(
$search1 = '/(
$search2 = '#(
$search3 = '#(
$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);//手機版圖片使用絕對路徑
{/dede:field.body}
內容頁上一篇下一篇標簽
官方最新版程序里,移動版下一篇有個BUG,官方還沒改過來,\include\arc.archives.class.php 找到
if(is_array($nextRow))
下面的
$preRow['id']
改成
$nextRow['id']
而移動版靜態或者偽靜態的上一篇和下一篇可以這樣輸出
{dede:prenext get=pre runphp=yes}
$preurl = @me;
preg_match('/aid=(\d*)/',$preurl,$match);
$result = GetOneArchive($match[1]);
@me = !empty($result) ? "上一篇:{$result['title']}" : "上一篇:沒有了";
{/dede:prenext}
{dede:prenext get=next runphp=yes}
$preurl = @me;
preg_match('/aid=(\d*)/',$preurl,$match);
$result = GetOneArchive($match[1]);
@me = !empty($result) ? "下一篇:{$result['title']}" : "下一篇:沒有了";
{/dede:prenext}
這樣更自由,可以修改文字,也可以單獨要url也行,要標題也行,而且不用去改動程序文件。
其他標簽跟電腦版一樣
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)首頁
2)列表
3)內容
完成。