dedecms中实现列表页面调用其它栏目的信息

群里有人问如何在dedecms中实现列表页面调用不同栏目的文章信息,以下给出解决方法,针对dedecms4.0。

首先,为dedecma增加一个标签的属性,我修改的标签为【List 标记】增加属性addonid,使用方法为:

addonid= '调用的栏目编号',不同的栏目请用半角“,”的分隔,这些栏目必须是最终列表栏目,同时不必在这个栏目编号中增加本栏目的编号。

例子:{dede:list pagesize='2' addonid='1,2'} {/dede:list}

继续修改include/inc_arclist_view.php,这个比较麻烦,不会的话,直接拷贝粘贴。

第一步,新增$addonid变量,如下:

class ListView
{
 var $dsql;
 var $dtp;
 var $dtp2;
 var $TypeID;
 var $TypeLink;
 var $PageNo;
 var $TotalPage;
 var $TotalResult;
 var $PageSize;
 var $ChannelUnit;
 var $ListType;
 var $Fields;
 var $PartView;
 var $StartTime;
 var $addonid; //这里为新增的变量

……

第二步:获得模板中的addonid的值,并且统计文章总数,修改function CountRecord()函数:

原本代码为:

  //------------------
  //统计列表里的记录
  //------------------
  function CountRecord()
  {
   global $cfg_list_son;
   //统计数据库记录
   $this->TotalResult = -1;
   if(isset($GLOBALS['TotalResult'])) $this->TotalResult = $GLOBALS['TotalResult'];
   if(isset($GLOBALS['PageNo'])) $this->PageNo = $GLOBALS['PageNo'];
   else $this->PageNo = 1;
   
   if($this->TotalResult==-1)
   {
     $addSql  = " arcrank > -1 ";
    
     if($cfg_list_son=='否') $addSql .= " And (typeid='".$this->TypeID."' or typeid2='".$this->TypeID."') ";
     else $addSql .= " And (".$this->TypeLink->GetSunID($this->TypeID,"#@__archives",$this->Fields['channeltype'])." Or #@__archives.typeid2='".$this->TypeID."') ";
    
     if($this->StartTime>0) $addSql .= " And senddate>'".$this->StartTime."'";
     $cquery = "Select count(*) as dd From #@__archives where $addSql";
    $row = $this->dsql->GetOne($cquery);
    if(is_array($row)) $this->TotalResult = $row['dd'];
    else $this->TotalResult = 0;
   }
   
   //初始化列表模板,并统计页面总数
   $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(!file_exists($tempfile)){
       $tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$GLOBALS['cfg_df_style']."/list_default.htm";
    }
   if(!file_exists($tempfile)||!is_file($tempfile)){
    echo "模板文件:'".$tempfile."' 不存在,无法解析文档!";
    exit();
   }
   $this->dtp->LoadTemplate($tempfile);
   $ctag = $this->dtp->GetTag("page");
   if(!is_object($ctag)){ $ctag = $this->dtp->GetTag("list"); }
   if(!is_object($ctag)) $this->PageSize = 20;
   else{
     if($ctag->GetAtt("pagesize")!="") $this->PageSize = $ctag->GetAtt("pagesize");
      else $this->PageSize = 20;
    }
    $this->TotalPage = ceil($this->TotalResult/$this->PageSize);
  }

修改为:

  //------------------
  //统计列表里的记录
  //------------------
  function CountRecord()
  {
   global $cfg_list_son;
  
   //初始化列表模板,并统计页面总数
   $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(!file_exists($tempfile)){
       $tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$GLOBALS['cfg_df_style']."/list_default.htm";
    }
   if(!file_exists($tempfile)||!is_file($tempfile)){
    echo "模板文件:'".$tempfile."' 不存在,无法解析文档!";
    exit();
   }
   $this->dtp->LoadTemplate($tempfile);
   $ctag = $this->dtp->GetTag("page");
   if(!is_object($ctag)){ $ctag = $this->dtp->GetTag("list"); }  
  if($ctag->GetAtt("addonid")!="") $this->addonid = $ctag->GetAtt("addonid");
   if(!is_object($ctag)) $this->PageSize = 20;
   else{
     if($ctag->GetAtt("pagesize")!="") {
     $this->PageSize = $ctag->GetAtt("pagesize");
   }
      else $this->PageSize = 20;
    }
 
   //统计数据库记录
   $this->TotalResult = -1;
   if(isset($GLOBALS['TotalResult'])) $this->TotalResult = $GLOBALS['TotalResult'];
   if(isset($GLOBALS['PageNo'])) $this->PageNo = $GLOBALS['PageNo'];
   else $this->PageNo = 1;
   
   if($this->TotalResult==-1)
   {
     $addSql  = " arcrank > -1 ";
    
  if($this->addonid!="") $isaddon = " Or #@__archives.typeid in (".$this->addonid.")";
  else $isaddon = "";
    
     if($cfg_list_son=='否') $addSql .= " And (typeid='".$this->TypeID."' or typeid2='".$this->TypeID."' ".$isaddon.") ";
     else $addSql .= " And (".$this->TypeLink->GetSunID($this->TypeID,"#@__archives",$this->Fields['channeltype'])." Or #@__archives.typeid2='".$this->TypeID."' ".$isaddon.") ";

    
     if($this->StartTime>0) $addSql .= " And senddate>'".$this->StartTime."'";
     $cquery = "Select count(*) as dd From #@__archives where $addSql";
    $row = $this->dsql->GetOne($cquery);
    if(is_array($row)) $this->TotalResult = $row['dd'];
    else $this->TotalResult = 0;
   }
 
    $this->TotalPage = ceil($this->TotalResult/$this->PageSize);
  }

说明,首先把统计数据库记录这部分代码后移,目的是为了利用获得的属性参数addonid,接着通过$this->addonid = $ctag->GetAtt("addonid");获得模板中的addonid的值,然后生成新的统计数据库的sql语句。

第三步,修改function GetArcList()函数,显示文档列表。

原文件为(代码片断):

  if($cfg_list_son=='否') $orwhere .= " And (arc.typeid='".$this->TypeID."' or arc.typeid2='".$this->TypeID."') ";
  else $orwhere .= " And (".$this->TypeLink->GetSunID($this->TypeID,"arc",$this->Fields['channeltype'])." Or arc.typeid2='".$this->TypeID."') ";

修改为:

  if($this->addonid!="") $isaddon = " Or arc.typeid in (".$this->addonid.")";
  else $isaddon = "";
  if($cfg_list_son=='否') $orwhere .= " And (arc.typeid='".$this->TypeID."' or arc.typeid2='".$this->TypeID."' ".$isaddon.") ";
  else $orwhere .= " And (".$this->TypeLink->GetSunID($this->TypeID,"arc",$this->Fields['channeltype'])." Or arc.typeid2='".$this->TypeID."' ".$isaddon.") ";

到此就可以实现列表页面调用其它栏目的信息。有问题的话Q我。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值