包子

木森技术分享

路漫漫其修远兮,吾将上下而求索。

您现在的位置是:网站首页 > DEDECMS

dede使用channelartlist在列表页和内容页调用同级栏目的方法

2021-03-13 23:04:26216

  使用 dede时,想在列表页和内容页调用同级栏目的文章,当然可以使用{ dede:channelartlist typeid=‘1’ row='5'}的方法,指定栏目id,但是要自动判断当前栏目的同级栏目就没办法了或者需要给每个顶级栏目分配一个模板,这样很麻烦。本文将给一种更简单的办法

  找到 \include\taglib\channelartlist.lib.php 文件

  查找: $attlist = 'typeid|0,row|20,cacheid|';

  修改为: $attlist = 'typeid|0,row|20,cacheid|,type|'; //这边加个 type 实现 在子栏目下调用 同级子栏目的信息

  然后查找:

if($typeid==0 || $typeid=='top') {
        $tpsql = " reid=0 AND ispart<>2 AND ishidden<>1 AND channeltype>0 ";
    }

  修改为:

if($type=='reid')    //调用上级目录下的子栏目内容
      {        
        $reid = $refObj->TypeLink->TypeInfos['reid'];          
        $tpsql = " reid='$reid' AND ispart<>2 AND ishidden<>1 ";
      }
    else if($typeid==0 || $typeid=='top') {
        $tpsql = " reid=0 AND ispart<>2 AND ishidden<>1 AND channeltype>0 ";
    }

  保存上面文件。然后在列表页或者内容页使用

  {dede:channelartlist type='reid' row='5'}

  底层循环代码

  {/dede:channelartlist} 就可以方便调用了。