dede子栏目下调用父栏目一级名称

2017-04-13 14:27:08 dedecms

可以在栏目列表页中根据是否有下级栏目显示父级栏目名称

安装说明:

新建php文件(命名为:parentchannel.lib.php),放入以下代码,将php文件放在/include/taglib 目录

使用方法

{dede:parentchannel}[field:typename/]{/dede:parentchannel}

<?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;

}

}

?>