织梦DEDECMS列表页首页怎么跟其它页使用不同模板

来源:undefined 2024-12-29 10:14:57 1029

织梦dedecms列表页首页怎么跟其它页使用不同模板?

织梦DEDECMS列表页首页跟其它页使用不同模板的办法

推荐学习:织梦cms

有些时候我们需要使列表页的首页跟第二页以及后面的页面的样式不同,修改dede:list标签又很难达到理想的效果,那么织梦猫就为大家介绍一个最简单的办法,就是为首页单独指定一个模板页,其余页面则调用另一个模板页。

修改的办法如下:

打开include目录下的arc.listview.class.php文件,找到Display函数(大约在397行),找到如下代码:

1

$this->ParseTempletsFirst();

登录后复制

在这些代码的上方添加以下代码:

1

2

3

4

5

if($this->PageNo>1)

{

$tempfile = $GLOBALS[cfg_basedir].$GLOBALS[cfg_templets_dir]."/".$GLOBALS[cfg_df_style]."/list_article2.htm";

$this->dtp->LoadTemplate($tempfile); 

}

登录后复制

添加之后,在页数大于1时,织梦就会调用list_article2.htm来作为列表页模板了。

添加以上代码后,在动态浏览栏目时已可以实现,但会发现生成栏目静态HTML页后,仍然没有达到预期目的,

搜索如下代码:

1

$this->ParseDMFields($this->PageNo,1);

登录后复制

在这句代码的上方添加以下代码:

1

2

3

4

5

6

if($this->PageNo>1)

{

$tempfile = $GLOBALS[cfg_basedir].$GLOBALS[cfg_templets_dir]."/".$GLOBALS[cfg_df_style]."/list_article2.htm";

$this->dtp->LoadTemplate($tempfile);

$this->ParseTempletsFirst(); 

}

登录后复制

可能还会有疑问,如果一个栏目有多个列表页模板,难道每个栏目列表页的第二页都用list_article2.htm来作为模板?

解决办法:

1

$tempfile = $GLOBALS[cfg_basedir].$GLOBALS[cfg_templets_dir]."/".$GLOBALS[cfg_df_style]."/list_article2.htm";

登录后复制

改为:

1

2

3

4

5

6

$tmpdir = $GLOBALS[cfg_basedir].$GLOBALS[cfg_templets_dir];

$tempfile = str_replace("{tid}",$this->TypeID,$this->Fields[templist]);

$tempfile = str_replace("{cid}",$this->ChannelUnit->ChannelInfos[nid],$tempfile);

$tempfile = $tmpdir."/".$tempfile;

$tmpfile2 = substr($tempfile,0,-4);

$tempfile = $tmpfile2."2.htm";

登录后复制

现在就会自动去获取列表页模板后面加了2的模板,例如列表页的模板是list_image.htm,那么第二页的模板就是list_image.htm。

这样,就方便多了。

以上就是织梦DEDECMS列表页首页怎么跟其它页使用不同模板的详细内容,更多请关注php中文网其它相关文章!

最新文章