前面文章介紹過dede織夢繫統實現釋出欄目和釋出文章後同時自動生成pc版和手機版靜態內容頁,這裡介紹釋出分類欄目頁同時生產手機版欄目頁。
工具/原料
dedecms
已按上一篇完整版修改過程式碼
方法/步驟
首先建立手機版的欄目模板,這裡自己建立,跟其他模板一樣,不過儲存路徑/templets/wap/list_infos.htm和/templets/wap/index_infos.htm,詳情看前面文章介紹
首先找到include目錄下的arc.sglistview.class.php,修改檔案前最好備份一下,找到function CountRecord
給函式加一個引數修改成 function CountRecord($iswap=0)
並在函式中235行左右 if(!file_exists($tempfile))前加入程式碼
if($iswap==1){
$tempfile = str_replace('/'.$GLOBALS['cfg_df_style'].'/',DEDEWAPTEMPLATESPATH,$tempfile);
}
找到函式function MakeHtml
把最後面
return $murl;修改成
$reurl=$murl;
$this->MakeWapHtml($startpage, $makepagesize, $isremote);
return $reurl;
新增函式MakeWapHtml
程式碼如下
function MakeWapHtml($startpage=1,$makepagesize=0)
{
global $cfg_arcdir;
if(empty($startpage))
{
$startpage = 1;
}
//建立封面模板檔案
if($this->TypeLink->TypeInfos['isdefault']==-1)
{
echo '這個類目是動態類目!';
return '';
}
//單獨頁面
else if($this->TypeLink->TypeInfos['ispart']>0)
{
$reurl = $this->MakePartTemplets();
return $reurl;
}
$this->CountRecord(1);
//初步給固定值的標記賦值
$this->ParseTempletsFirst();
$totalpage = ceil($this->TotalResult/$this->PageSize);
if($totalpage==0)
{
$totalpage = 1;
}
CreateDir(MfTypedir($this->Fields['typedir']));
$murl = '';
if($makepagesize > 0)
{
$endpage = $startpage+$makepagesize;
}
else
{
$endpage = ($totalpage+1);
}
if( $endpage >= $totalpage+1 )
{
$endpage = $totalpage+1;
}
if($endpage==1)
{
$endpage = 2;
}
for($this->PageNo=$startpage; $this->PageNo < $endpage; $this->PageNo++)
{
$this->ParseDMFields($this->PageNo,1);
$makeFile = $this->GetMakeFileRule($this->Fields['id'],'list',$this->Fields['typedir'],'',$this->Fields['namerule2']);
$makeFile = str_replace("{page}",$this->PageNo,$makeFile);
$murl = $makeFile;
if(!preg_match("/^\//",$makeFile))
{
$makeFile = "/".$makeFile;
}
$makeFile = $this->GetTruePath().$makeFile;
$makeFile = preg_replace("/\/{1,}/", "/", $makeFile);
$makeFile=str_replace($cfg_arcdir.'/',DEDEWAPPATH . '/',$makeFile);
$murl = $this->GetTrueUrl($murl);
$this->dtp->SaveTo($makeFile);
}
if($startpage==1)
{
//如果列表啟用封面檔案,複製這個檔案第一頁
if($this->TypeLink->TypeInfos['isdefault']==1
&& $this->TypeLink->TypeInfos['ispart']==0)
{
$onlyrule = $this->GetMakeFileRule($this->Fields['id'],"list",$this->Fields['typedir'],'',$this->Fields['namerule2']);
$onlyrule = str_replace("{page}","1",$onlyrule);
$list_1 = $this->GetTruePath().$onlyrule;
$list_1=str_replace($cfg_arcdir.'/',DEDEWAPPATH . '/',$list_1);
$murl = MfTypedir($this->Fields['typedir']).'/'.$this->Fields['defaultname'];
$indexname = $this->GetTruePath().$murl;
$indexname=str_replace($cfg_arcdir.'/',DEDEWAPPATH . '/',$indexname);
copy($list_1,$indexname);
}
}
}
找到函式 function MakePartTemplets
修改最後面的程式碼
return $this->GetTrueUrl($makeUrl);修改成
$returl=$this->GetTrueUrl($makeUrl);
$this->MakeWapPartTemplets();
return $returl;
新增函式function MakeWapPartTemplets()
程式碼如下
function MakeWapPartTemplets()
{
global $cfg_df_style,$cfg_arcdir;
$this->PartView = new PartView($this->TypeID,false);
$this->PartView->SetTypeLink($this->TypeLink);
$nmfa = 0;
$tmpdir = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir'];
if($this->Fields['ispart']==1)
{
$tempfile = str_replace("{tid}",$this->TypeID,$this->Fields['tempindex']);
$tempfile = str_replace("{cid}",$this->ChannelUnit->ChannelInfos['nid'],$tempfile);
$tempfile = $tmpdir."/".$tempfile;
$tempfile=str_replace('/'.$GLOBALS['cfg_df_style'].'/',DEDEWAPTEMPLATESPATH,$tempfile);
if(!file_exists($tempfile))
{
$tempfile = $tmpdir."/".$GLOBALS['cfg_df_style']."/index_default_sg.htm";
}
$this->PartView->SetTemplet($tempfile);
}
else if($this->Fields['ispart']==2)
{
//跳轉網址
return $this->Fields['typedir'];
}
CreateDir(MfTypedir($this->Fields['typedir']));
$makeUrl = $this->GetMakeFileRule($this->Fields['id'],"index",MfTypedir($this->Fields['typedir']),$this->Fields['defaultname'],$this->Fields['namerule2']);
$makeUrl = preg_replace("/\/{1,}/", "/", $makeUrl);
$makeFile = $this->GetTruePath().$makeUrl;
$makeFile=str_replace($cfg_arcdir.'/',DEDEWAPPATH . '/',$makeFile);
if($nmfa==0)
{
$this->PartView->SaveToHtml($makeFile);
}
else
{
if(!file_exists($makeFile))
{
$this->PartView->SaveToHtml($makeFile);
}
}
}
注意事項
必須按照上一篇文章添加了模板目錄和生成目錄變數
分類文章生成靜態頁在上一篇完整版已完成