洞悉互聯網前沿資訊,探尋網站營銷規律
作者:狐靈科技 | 2019-12-24 10:29 |點擊:
前面有教程講到欄目列表頁第一個文檔與其他文檔不同教程《織夢列表頁 第一篇文章與其他文章樣式不同》
這次教程實現的是第一頁的模板與其他第二頁、第三頁、、、后面的頁調用的不同模板,分開為2個欄目列表模板,此教程支持欄目頁動態、靜態、偽靜態下使用。
打開 /include/arc.listview.class.php 找到,大概在第330行
$this->ParseDMFields($this->PageNo,1);
在它的上面加入
$tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$this->TypeLink->TypeInfos['templist'];
$tempfile = str_replace("{tid}", $this->TypeID, $tempfile);
$tempfile = str_replace("{cid}", $this->ChannelUnit->ChannelInfos['nid'], $tempfile);
if ( defined('DEDEMOB') )
{
$tempfile =str_replace('.htm','_m.htm',$tempfile);
}
if(!file_exists($tempfile))
{
$tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$GLOBALS['cfg_df_style']."/list_default.htm";
if ( defined('DEDEMOB') )
{
$tempfile =str_replace('.htm','_m.htm',$tempfile);
}
}
if(!file_exists($tempfile)||!is_file($tempfile))
{
echo $this->Fields['typename']." [ID:{$this->TypeID}] ".$GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$this->TypeLink->TypeInfos['templist']."模板文件不存在,無法解析文檔!";
exit();
}
if( $this->PageNo===1 )
{
$tempfile2 =str_replace('.htm','_1.htm',$tempfile);
if(file_exists($tempfile2) && is_file($tempfile2))
{
$this->dtp->LoadTemplate($tempfile2);
$this->ParseTempletsFirst();
}
}
else
{
$this->dtp->LoadTemplate($tempfile);
}
如圖
繼續找到,大概在第450行的
$this->ParseTempletsFirst();
注意是在第450行左右的這個代碼,因為這個代碼有3處,請認準是在大概第450行上這個
找到后在它的上面加入
$tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$this->TypeLink->TypeInfos['templist'];
$tempfile = str_replace("{tid}", $this->TypeID, $tempfile);
$tempfile = str_replace("{cid}", $this->ChannelUnit->ChannelInfos['nid'], $tempfile);
if ( defined('DEDEMOB') )
{
$tempfile =str_replace('.htm','_m.htm',$tempfile);
}
if(!file_exists($tempfile))
{
$tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$GLOBALS['cfg_df_style']."/list_default.htm";
if ( defined('DEDEMOB') )
{
$tempfile =str_replace('.htm','_m.htm',$tempfile);
}
}
if(!file_exists($tempfile)||!is_file($tempfile))
{
echo $this->Fields['typename']." [ID:{$this->TypeID}] ".$GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$this->TypeLink->TypeInfos['templist']."模板文件不存在,無法解析文檔!";
exit();
}
if( $this->PageNo===1 )
{
$tempfile2 =str_replace('.htm','_1.htm',$tempfile);
if(file_exists($tempfile2) && is_file($tempfile2))
{
$this->dtp->LoadTemplate($tempfile2);
}
}
else
{
$this->dtp->LoadTemplate($tempfile);
}
如圖
第一頁模板,在原欄目列表模板后面加_1
例如,原列表模板是 list_dongwu.htm
如果你想讓第一頁跟list_dongwu.htm不一樣的話,你可以建立一個
list_dongwu_1.htm
系統在動態或者生成靜態時,欄目列表第一頁優先去找這個 _1 的第一頁模板文件,存在就輸出,不存在就使用默認的原列表模板 list_dongwu.htm
更新系統緩存,靜態的生成,動態的直接查看效果