怎么在织梦dede栏目列表或者dede子栏目列表调用DEDE调用父栏目名称?DEDECMS调用父栏目名称、DEDECMS调用子栏目里的父栏目名称的方法
方法如下:
新建一个php文件,命名为:parentcannel.lib.php,然后在此文件写入以下代码:
<?php
function lib_parentchannel(&$ctag,&$refObj)
{
global $_sys_globals,$dsql;
$attlist = "row|100,nosonmsg|,col|1";
FillAttsDefault($ctag->CAttribute->Items,$attlist);
extract($ctag->CAttribute->Items, EXTR_SKIP);
$innertext = $ctag->GetInnerText();
$reid = 0;
$topid = 0;
//如果属性里没指定栏目id,从引用类里获取栏目信息
if(empty($typeid))
{
if( isset($refObj->TypeLink->TypeInfos['id']) )
{
$typeid = $refObj->TypeLink->TypeInfos['id'];
$reid = $refObj->TypeLink->TypeInfos['reid'];
$topid = $refObj->TypeLink->TypeInfos['topid'];
}
else {
$typeid = 0;
}
} //如果指定了栏目id,从数据库获取栏目信息
else
{
$row2 = $dsql->GetOne("SELECT * FROM `dede_arctype` WHERE id='$typeid' ");
$typeid = $row2['id'];
$reid = $row2['reid'];
$topid = $row2['topid'];
$issetInfos = true;
}
$sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath
FROM `dede_arctype` WHERE reid='$typeid' AND ishidden<>1 ORDER BY sortrank ASC LIMIT 1";
$dsql->SetQuery($sql);
$dsql->Execute();
$totalRow = $dsql->GetTotalRow();
//And id<>'$typeid'
$row = $dsql->GetOne("SELECT id,typename,reid,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath
FROM `dede_arctype` WHERE id='$typeid' ");
if(!is_array($row)) return '';
if($totalRow==0){
$typeid = $row['reid'];
$row = $dsql->GetOne("SELECT id,typename,reid,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath
FROM `dede_arctype` WHERE id='$typeid' ");
if(!is_array($row)) return '';
}
if(trim($innertext)=='') $innertext = GetSysTemplets("part_type_list.htm");
$dtp = new DedeTagParse();
$dtp->SetNameSpace('field','[',']');
$dtp->LoadSource($innertext);
if(!is_array($dtp->CTags))
{
unset($dtp);
return '';
}
else
{
$row['typelink'] = $row['typeurl'] = GetOneTypeUrlA($row);
foreach($dtp->CTags as $tagid=>$ctag)
{
if(isset($row[$ctag->GetName()])) $dtp->Assign($tagid,$row[$ctag->GetName()]);
}
$revalue = $dtp->GetResult();
unset($dtp);
return $revalue;
}
}
?>
然后在htm文件里用以下代码进行调用:
{dede:parentchannel}[field:typename/]{/dede:parentchannel}
此方法可以用在栏目列表页中根据是否有下级栏目显示父级栏目名称。