织梦侠
WWW.2L3.NET

织梦dede调用四级栏目

织梦调用四级子栏目,首先需要修改文件:\include\taglib\channel.lib.php,请将以下代码全部复制替换上述文件:
  1. <?php
  2. function lib_channel(&$ctag,&$refObj)
  3. {
  4. global $_sys_globals,$envs,$dsql;
  5. $attlist = "typeid|0,reid|0,row|100,col|1,type|son,currentstyle|";
  6. FillAttsDefault($ctag->CAttribute->Items,$attlist);
  7. extract($ctag->CAttribute->Items, EXTR_SKIP);
  8. $innertext = $ctag->GetInnerText();
  9. $cacheid = trim($cacheid);
  10. if($cacheid !='') {
  11. $likeType = GetCacheBlock($cacheid);
  12. if($likeType != '') return $likeType;
  13. }
  14.  
  15. $reid = 0;
  16. $topid = 0;
  17. if(empty($typeid) && $envs['typeid']!=0)
  18. {
  19. $typeid = $envs['typeid'];
  20. $reid = $envs['reid'];
  21. }else{
  22. $reid=0;
  23. }
  24. if($type==''||$type=='sun') $type="son";
  25. if($innertext=='') $innertext = GetSysTemplets("channel_list.htm");
  26. if($reid==0 && $typeid>0)
  27. {
  28. $dbrow = $dsql->GetOne("Select reid From dede_arctype where id='$typeid' ");
  29. if(is_array($dbrow)) $reid = $dbrow['reid'];
  30. }
  31. $likeType = '';
  32. if($type=='top')
  33. {
  34. $sql = "Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,description
  35. From dede_arctype where reid=0 And ishidden<>1 order by sortrank asc limit 0,$row";
  36. }
  37. else if($type=="son")
  38. {
  39. //if($_sys_globals['typeid']>0) $typeid = $_sys_globals['typeid'];
  40. if($typeid==0) {
  41. return '';
  42. }
  43. $sql = "Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,description
  44. From dede_arctype where reid='$typeid' And ishidden<>1 order by sortrank asc limit 0,$row";
  45. }
  46. else if($type=="self")
  47. {
  48. if($reid==0) {
  49. return '';
  50. }
  51. $sql = "Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,description
  52. From `dede_arctype` where reid='$reid' And ishidden<>1 order by sortrank asc limit 0,$row";
  53. }
  54. //And id<>'$typeid'
  55. $needRel = false;
  56. $dtp2 = new DedeTagParse();
  57. $dtp2->SetNameSpace("field","[","]");
  58. $dtp2->LoadSource($innertext);
  59. $dsql2 = clone $dsql;
  60. $dsql->SetQuery($sql);
  61. $dsql->Execute();
  62. $line = $row;
  63. //检查是否有子栏目,并返回rel提示(用于二级菜单)
  64. if(ereg(':rel', $innertext)) $needRel = true;
  65.  
  66. if(empty($sql)) return '';
  67. $dsql->SetQuery($sql);
  68. $dsql->Execute();
  69.  
  70. $totalRow = $dsql->GetTotalRow();
  71. $GLOBALS['autoindex'] = 0;
  72. for($i=0;$i < $line;$i++)
  73. {
  74. if($col>1) $likeType .= "<dl>\r\n";
  75. for($j=0;$j<$col;$j++)
  76. {
  77. if($col>1) $likeType .= "<dd>\r\n";
  78. if($row=$dsql->GetArray())
  79. {
  80. $row['sonids'] = $row['rel'] = '';
  81. if($needRel)
  82. {
  83. $row['sonids'] = GetSonIds($row['id'], 0, false);
  84. if($row['sonids']=='') $row['rel'] = '';
  85. else $row['rel'] = " rel='dropmenu{$row['id']}'";
  86. }
  87. //处理同级栏目中,当前栏目的样式
  88. if( ($row['id']==$typeid || ($topid==$row['id'] && $type=='top') ) && $currentstyle!='' )
  89. {
  90. if($currentstyle!='')
  91. {
  92. $linkOkstr = $currentstyle;
  93. $row['typelink'] = GetOneTypeUrlA($row);
  94. $linkOkstr = str_replace("~rel~",$row['rel'],$linkOkstr);
  95. $linkOkstr = str_replace("~id~",$row['id'],$linkOkstr);
  96. $linkOkstr = str_replace("~typelink~",$row['typelink'],$linkOkstr);
  97. $linkOkstr = str_replace("~typename~",$row['typename'],$linkOkstr);
  98. $likeType .= $linkOkstr;
  99. }
  100. }else
  101. {
  102. $row['typelink'] = $row['typeurl'] = GetOneTypeUrlA($row);
  103. if(is_array($dtp2->CTags))
  104. {
  105. foreach($dtp2->CTags as $tagid=>$ctag){
  106. if(isset($row[$ctag->GetName()]))
  107. {
  108. $dtp2->Assign($tagid,$row[$ctag->GetName()]);
  109. }
  110. elseif (preg_match('/^sonchannel[0-9]*$/',$ctag->GetName()))
  111. {
  112. $dtp2->Assign($tagid,lib_channel_son($ctag,$row['id'],$dsql2));
  113. }
  114. }
  115. }
  116. $likeType .= $dtp2->GetResult();
  117. }
  118. }
  119. if($col>1) $likeType .= "</dd>\r\n";
  120. $GLOBALS['autoindex']++;
  121. }//Loop Col
  122. if($col>1)
  123. {
  124. $i += $col - 1;
  125. $likeType .= " </dl>\r\n";
  126. }
  127. }//Loop for $i
  128. reset($dsql2);
  129. $dsql->FreeResult();
  130. return $likeType;
  131. }
  132. function lib_channel_son($ctag,$typeid = 0,$dsql2)
  133. {
  134. $attlist = "row|100,col|1,currentstyle|";
  135. FillAttsDefault($ctag->CAttribute->Items,$attlist);
  136. extract($ctag->CAttribute->Items, EXTR_SKIP);
  137. $innertext = $ctag->GetInnerText();
  138. $dsql3 = clone $dsql2;
  139. $likeType = '';
  140. //if($_sys_globals['typeid']>0) $typeid = $_sys_globals['typeid'];
  141. if($typeid==0) {
  142. return '';
  143. }
  144. $sql = "Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,description
  145. From dede_arctype where reid='$typeid' And ishidden<>1 order by sortrank asc limit 0,$row";
  146. //And id<>'$typeid'
  147. $dtp2 = new DedeTagParse();
  148. $dtp2->SetNameSpace("field","[","]");
  149. $dtp2->LoadSource($innertext);
  150. $dsql2->SetQuery($sql);
  151. $dsql2->Execute();
  152. $line = $row;
  153. for($i=0;$i < $line;$i++)
  154. {
  155. if($col>1) $likeType .= "<dl>\r\n";
  156. for($j=0;$j<$col;$j++)
  157. {
  158. if($col>1) $likeType .= "<dd>\r\n";
  159. if($row=$dsql2->GetArray())
  160. {
  161. $row['typelink'] = $row['typeurl'] = GetOneTypeUrlA($row);
  162. if(is_array($dtp2->CTags))
  163. {
  164. foreach($dtp2->CTags as $tagid=>$ctag){
  165. if(isset($row[$ctag->GetName()]))
  166. {
  167. $dtp2->Assign($tagid,$row[$ctag->GetName()]);
  168. }
  169. elseif (preg_match('/^sonchannel[0-9]*$/',$ctag->GetName()))
  170. {
  171. $dtp2->Assign($tagid,lib_channel_son($ctag,$row['id'],$dsql3));
  172. }
  173. }
  174. }
  175. $likeType .= $dtp2->GetResult();
  176. }
  177. if($col>1) $likeType .= "</dd>\r\n";
  178. }//Loop Col
  179. if($col>1)
  180. {
  181. $i += $col - 1;
  182. $likeType .= " </dl>\r\n";
  183. }
  184. }//Loop for $i
  185. reset($dsql3);
  186. $dsql2->FreeResult();
  187. return $likeType;
  188. }
  189. ?>
 
 
 
2、在模板中调用实例:
  1. {dede:channel type='son' typeid='3'}
  2. [field:typename/]
  3. <ul>
  4. [field:sonchannel0]
  5. <li><a href="[field:typelink/]">[field:typename/]</a></li>
  6. [field:sonchannel1]
  7. <li><a href="[field:typelink/]">---[field:typename/]</a></li>
  8. [field:sonchannel2]
  9. <li><a href="[field:typelink/]">===[field:typename/]</a></li>
  10. [field:sonchannel3]
  11. <li><a href="[field:typelink/]">===[field:typename/]</a></li>
  12. [/field:sonchannel3]
  13. [/field:sonchannel2]
  14. [/field:sonchannel1]
  15. [/field:sonchannel0]
  16. </ul>
  17. {/dede:channel}
转载请注明文章来自织梦侠[秩名]作者的-织梦dede调用四级栏目
联系作者
取消
这个作者很懒什么也没留下!
打赏作者
取消

本文作者无偿奉献,就打赏给我们织梦侠吧!

扫码支付
扫码打赏,建议金额1-10元

打开支付宝扫一扫,即可进行扫码打赏哦

提醒:打赏金额将直接进入对方账号,无法退款,请您谨慎操作。