Skip to main content
 Web开发网 » 站长学院 » 织梦教程

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

2021年08月31日7310百度已收录

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

  修改的办法如下:

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

  $this->ParseTempletsFirst();

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

  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页后,仍然没有达到预期目的,

  搜索如下代码:

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

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

  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();

  好了,现在无论是静态页还是动态页都达到理想的效果了。

  可能还会有疑问,如果一(来作为模板?

  解决办法:

  将

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

  改为:

  $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。

  这样,就方便多了。

评论列表暂无评论
发表评论
微信