dede在任一子级栏目获取顶级栏目名称 typename,包括该顶级栏目下

夏夜,蟋蟀劲鸣,星光灿烂,月光清澈。孩提时的晨在小山上快活的玩味着每一朵花,每一株草,亦或躺在绿油油的草地数星星。一切都是那么的美好,那么的惬意。

找到 include/taglib/type.lib.php , 复制, 重命名为toptype.lib.php

查找 function lib_type(&$ctag,&$refObj)

修改为:

function lib_toptype(&$ctag,&$refObj)

查找$row = $dsql->GetOne

注释掉//$row = $dsql->GetOne("Select id,topid,description,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,typelitpic From `dede_arctype` where id='$typeid' ");

添加3行:

$topid=$dsql->GetOne("Select topid From `dede_arctype` where id='$typeid' "); $topid=$topid['topid']; $row=$dsql->GetOne("Select id,topid,description,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,typelitpic From `dede_arctype` where id='$topid' ");

模板调用:{dede:toptype}[field:typename/]{/dede:toptype}

修改后的toptype.lib.php

<?php
if(!defined('DEDEINC'))exit('Request Error!');
functionlib_toptype(&$ctag,&$refObj)
{
global$dsql,$envs;
$attlist='typeid|0';
FillAttsDefault($ctag->CAttribute->Items,$attlist);
extract($ctag->CAttribute->Items, EXTR_SKIP);
$innertext= trim($ctag->GetInnerText());
if($typeid==0) {
$typeid= ( isset($refObj->TypeLink->TypeInfos['id']) ?$refObj->TypeLink->TypeInfos['id'] :$envs['typeid'] );
}
if(empty($typeid))return'';
//$row = $dsql->GetOne("Select id,topid,description,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,typelitpic From `dede_arctype` where id='$typeid' ");
$topid=$dsql->GetOne("Select topid From `dede_arctype` where id='$typeid' ");
$topid=$topid['topid'];
$row=$dsql->GetOne("Select id,topid,description,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,typelitpic From `dede_arctype` where id='$topid' ");
if(!is_array($row))return'';
if($row['topid']==0){$row['topid']=$row['id'];}
if(trim($innertext)=='')$innertext= GetSysTemplets("part_type_list.htm");
$dtp=newDedeTagParse();
$dtp->SetNameSpace('field','[',']');
$dtp->LoadSource($innertext);
if(!is_array($dtp->CTags))
{
unset($dtp);
return'';
}
else
{
$row['typelink'] =$row['typeurl'] = GetOneTypeUrlA($row);
foreach($dtp->CTagsas$tagid=>$ctag)
{
if(isset($row[$ctag->GetName()]))$dtp->Assign($tagid,$row[$ctag->GetName()]);
}
$revalue=$dtp->GetResult();
unset($dtp);
return$revalue;
}
}

?>

如果想获取任一栏目的上级栏目,可将topid---->改为--->reid,最后记得改函数名和文件名

retype.lib.php

<?php
if(!defined('DEDEINC')) exit('Request Error!');
function lib_retype(&$ctag,&$refObj)
{
global $dsql,$envs;
$attlist='typeid|0';
FillAttsDefault($ctag->CAttribute->Items,$attlist);
extract($ctag->CAttribute->Items, EXTR_SKIP);
$innertext = trim($ctag->GetInnerText());
if($typeid==0) {
$typeid = ( isset($refObj->TypeLink->TypeInfos['id']) ? $refObj->TypeLink->TypeInfos['id'] : $envs['typeid'] );
}
if(empty($typeid)) return '';
//$row = $dsql->GetOne("Select id,topid,description,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,typelitpic From `dede_arctype` where id='$typeid' ");
$reid=$dsql->GetOne("Select reid From `dede_arctype` where id='$typeid' ");
$reid=$reid['reid'];
$row=$dsql->GetOne("Select id,reid,description,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,typelitpic From `dede_arctype` where id='$reid' ");
if(!is_array($row)) return '';
if($row['reid']==0){$row['reid']=$row['id'];}
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;
}
}

?>
模板调用:{dede:retype}[field:typename/]{/dede:retype}

到此这篇关于dede在任一子级栏目获取顶级栏目名称 typename,包括该顶级栏目下就介绍到这了。这个世界上从来没有一蹴而就的成功,如果没有踏实的努力,没有点滴的积累,再好的运气降落到你头上时,你也没有接住它的实力。早安!与您共勉,人生需要一步一个脚印!更多相关dede在任一子级栏目获取顶级栏目名称 typename,包括该顶级栏目下内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!

您可能有感兴趣的文章
dedecms如何实现任意页面调用当前会员信息的方

织梦dede:tag调用指定多个栏目的TAG标签

DedeCMS织梦判断是否有二级栏目输出HTML代码

织梦dede数据还原更新缓存也生成了为什么首页不对

织梦dede文档置顶并显示置顶文字或图标