做网站在二级页面需要 获得 从一级页面点进来的链接 的 顶级栏目名称,但dede给的标签貌似只能获得一串名称(顶级/二级/某链接)这样的,所以上网查了一些资料,找到个比较靠谱的。
1、新建一个文件叫 parentchannel.lib.php
1 <?php 2 3 /** 4 5 * 父栏目调用标签 6 7 * 8 9 * @version $Id: parentchannel.lib.php 1 9:29 2010年7月6日Z tianya $ 10 11 * @package DedeCMS.Taglib 12 13 * @copyright Copyright (c) 2007 - 2010, DesDev, Inc. 14 15 * @license http://help.dedecms.com/usersguide/license.html 16 17 * @link http://www.dedecms.com 18 19 */ 20 21 22 /*>>dede>> 23 24 <name>父栏目标签</name> 25 26 <type>全局标记</type> 27 28 <for>V55,V56,V57</for> 29 30 <description>父栏目调用标签</description> 31 32 <demo> 33 34 {dede:parentchannel} 35 36 <a href='[field:typeurl/]'>[field:typename/]</a> 37 38 {/dede:parentchannel} 39 40 </demo> 41 42 <attributes> 43 44 <iterm>typeid:指定栏目ID</iterm> 45 46 </attributes> 47 48 >>dede>>*/ 49 50 51 function lib_parentchannel(&$ctag,&$refObj) 52 53 { 54 55 global $_sys_globals,$dsql; 56 57 58 $attlist = "row|100,nosonmsg|,col|1"; 59 60 FillAttsDefault($ctag->CAttribute->Items,$attlist); 61 62 extract($ctag->CAttribute->Items, EXTR_SKIP); 63 64 $innertext = $ctag->GetInnerText(); 65 66 67 68 $reid = 0; 69 70 $topid = 0; 71 72 //如果属性里没指定栏目id,从引用类里获取栏目信息 73 74 if(empty($typeid)) 75 76 { 77 78 if( isset($refObj->TypeLink->TypeInfos['id']) ) 79 80 { 81 82 $typeid = $refObj->TypeLink->TypeInfos['id']; 83 84 $reid = $refObj->TypeLink->TypeInfos['reid']; 85 86 $topid = $refObj->TypeLink->TypeInfos['topid']; 87 88 } 89 90 else { 91 92 $typeid = 0; 93 94 } 95 96 } //如果指定了栏目id,从数据库获取栏目信息 97 98 else 99 100 { 101 102 $row2 = $dsql->GetOne("SELECT * FROM `#@__arctype` WHERE id='$typeid' "); 103 104 $typeid = $row2['id']; 105 106 $reid = $row2['reid']; 107 108 $topid = $row2['topid']; 109 110 $issetInfos = true; 111 112 } 113 114 115 $sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath 116 117 FROM `#@__arctype` WHERE reid='$typeid' AND ishidden<>1 ORDER BY sortrank ASC LIMIT 1"; 118 119 $dsql->SetQuery($sql); 120 121 $dsql->Execute(); 122 123 $totalRow = $dsql->GetTotalRow(); 124 125 126 127 //And id<>'$typeid' 128 129 $row = $dsql->GetOne("SELECT id,typename,reid,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath 130 131 FROM `#@__arctype` WHERE id='$typeid' "); 132 133 if(!is_array($row)) return ''; 134 135 if($totalRow==0){ 136 137 $typeid = $row['reid']; 138 139 $row = $dsql->GetOne("SELECT id,typename,reid,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath 140 141 FROM `#@__arctype` WHERE id='$typeid' "); 142 143 if(!is_array($row)) return ''; 144 145 } 146 147 if(trim($innertext)=='') $innertext = GetSysTemplets("part_type_list.htm"); 148 149 150 $dtp = new DedeTagParse(); 151 152 $dtp->SetNameSpace('field','[',']'); 153 154 $dtp->LoadSource($innertext); 155 156 if(!is_array($dtp->CTags)) 157 158 { 159 160 unset($dtp); 161 162 return ''; 163 164 } 165 166 else 167 168 { 169 170 $row['typelink'] = $row['typeurl'] = GetOneTypeUrlA($row); 171 172 foreach($dtp->CTags as $tagid=>$ctag) 173 174 { 175 176 if(isset($row[$ctag->GetName()])) $dtp->Assign($tagid,$row[$ctag->GetName()]); 177 178 } 179 180 $revalue = $dtp->GetResult(); 181 182 unset($dtp); 183 184 return $revalue; 185 186 } 187 188 } 189 190 ?>
放到\include\taglib下
2、{dede:parentchannel}[field:typename/]{/dede:parentchannel}调用
OK!