DEDECMS子栏目页面和内容页调用顶级栏目

来自:互联网
时间:2018-09-01
阅读:
免费资源网 - https://freexyz.cn/

新建一个文件 “/include/taglib/type2.lib.php”,代码如下:

<?php   if(!defined('DEDEINC')) exit('Request Error!'); 
function lib_type2(&$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(emptyempty($typeid)) return ''; 
 
    $row = $dsql->GetOne("SELECT id,topid,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath  
                          FROM `#@__arctype` WHERE id='$typeid' "); 
    if(!is_array($row)) return ''; 
    if($row['topid']==0){$row['topid']=$row['id'];} //文章页获取顶级栏目ID(topid) 
    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:type2} 
<a href="[field:typelink /]">[field:typename /]</a> 
{/dede:type2}
免费资源网 - https://freexyz.cn/
返回顶部
顶部