您的位置:首页 > 其它

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

2012-07-18 09:42 302 查看
群里有人问如何在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.") ";
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: