找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 892|回复: 0

[分享] 织梦如何调用四级栏目

[复制链接]
发表于 2018-7-26 09:05:02 | 显示全部楼层 |阅读模式 来自 河南省新乡市
织梦调用四级子栏目,首先需要修改文件:\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. $reid = 0;
  15. $topid = 0;
  16. if(empty($typeid) && $envs['typeid']!=0)
  17. {
  18. $typeid = $envs['typeid'];
  19. $reid = $envs['reid'];
  20. }else{
  21. $reid=0;
  22. }
  23. if($type==''||$type=='sun') $type="son";
  24. if($innertext=='') $innertext = GetSysTemplets("channel_list.htm");
  25. if($reid==0 && $typeid>0)
  26. {
  27. $dbrow = $dsql->GetOne("Select reid From dede_arctype where id='$typeid' ");
  28. if(is_array($dbrow)) $reid = $dbrow['reid'];
  29. }
  30. $likeType = '';
  31. if($type=='top')
  32. {
  33. $sql = "Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,description
  34. From dede_arctype where reid=0 And ishidden<>1 order by sortrank asc limit 0,$row";
  35. }
  36. else if($type=="son")
  37. {
  38. //if($_sys_globals['typeid']>0) $typeid = $_sys_globals['typeid'];
  39. if($typeid==0) {
  40. return '';
  41. }
  42. $sql = "Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,description
  43. From dede_arctype where reid='$typeid' And ishidden<>1 order by sortrank asc limit 0,$row";
  44. }
  45. else if($type=="self")
  46. {
  47. if($reid==0) {
  48. return '';
  49. }
  50. $sql = "Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,description
  51. From `dede_arctype` where reid='$reid' And ishidden<>1 order by sortrank asc limit 0,$row";
  52. }
  53. //And id<>'$typeid'
  54. $needRel = false;
  55. $dtp2 = new DedeTagParse();
  56. $dtp2->SetNameSpace("field","[","]");
  57. $dtp2->LoadSource($innertext);
  58. $dsql2 = clone $dsql;
  59. $dsql->SetQuery($sql);
  60. $dsql->Execute();
  61. $line = $row;
  62. //检查是否有子栏目,并返回rel提示(用于二级菜单)
  63. if(ereg(':rel', $innertext)) $needRel = true;

  64. if(empty($sql)) return '';
  65. $dsql->SetQuery($sql);
  66. $dsql->Execute();

  67. $totalRow = $dsql->GetTotalRow();
  68. $GLOBALS['autoindex'] = 0;
  69. for($i=0;$i < $line;$i++)
  70. {
  71. if($col>1) $likeType .= "<dl>\r\n";
  72. for($j=0;$j<$col;$j++)
  73. {
  74. if($col>1) $likeType .= "<dd>\r\n";
  75. if($row=$dsql->GetArray())
  76. {
  77. $row['sonids'] = $row['rel'] = '';
  78. if($needRel)
  79. {
  80. $row['sonids'] = GetSonIds($row['id'], 0, false);
  81. if($row['sonids']=='') $row['rel'] = '';
  82. else $row['rel'] = " rel='dropmenu{$row['id']}'";
  83. }
  84. //处理同级栏目中,当前栏目的样式
  85. if( ($row['id']==$typeid || ($topid==$row['id'] && $type=='top') ) && $currentstyle!='' )
  86. {
  87. if($currentstyle!='')
  88. {
  89. $linkOkstr = $currentstyle;
  90. $row['typelink'] = GetOneTypeUrlA($row);
  91. $linkOkstr = str_replace("~rel~",$row['rel'],$linkOkstr);
  92. $linkOkstr = str_replace("~id~",$row['id'],$linkOkstr);
  93. $linkOkstr = str_replace("~typelink~",$row['typelink'],$linkOkstr);
  94. $linkOkstr = str_replace("~typename~",$row['typename'],$linkOkstr);
  95. $likeType .= $linkOkstr;
  96. }
  97. }else
  98. {
  99. $row['typelink'] = $row['typeurl'] = GetOneTypeUrlA($row);
  100. if(is_array($dtp2->CTags))
  101. {
  102. foreach($dtp2->CTags as $tagid=>$ctag){
  103. if(isset($row[$ctag->GetName()]))
  104. {
  105. $dtp2->Assign($tagid,$row[$ctag->GetName()]);
  106. }
  107. elseif (preg_match('/^sonchannel[0-9]*$/',$ctag->GetName()))
  108. {
  109. $dtp2->Assign($tagid,lib_channel_son($ctag,$row['id'],$dsql2));
  110. }
  111. }
  112. }
  113. $likeType .= $dtp2->GetResult();
  114. }
  115. }
  116. if($col>1) $likeType .= "</dd>\r\n";
  117. $GLOBALS['autoindex']++;
  118. }//Loop Col
  119. if($col>1)
  120. {
  121. $i += $col - 1;
  122. $likeType .= " </dl>\r\n";
  123. }
  124. }//Loop for $i
  125. reset($dsql2);
  126. $dsql->FreeResult();
  127. return $likeType;
  128. }
  129. function lib_channel_son($ctag,$typeid = 0,$dsql2)
  130. {
  131. $attlist = "row|100,col|1,currentstyle|";
  132. FillAttsDefault($ctag->CAttribute->Items,$attlist);
  133. extract($ctag->CAttribute->Items, EXTR_SKIP);
  134. $innertext = $ctag->GetInnerText();
  135. $dsql3 = clone $dsql2;
  136. $likeType = '';
  137. //if($_sys_globals['typeid']>0) $typeid = $_sys_globals['typeid'];
  138. if($typeid==0) {
  139. return '';
  140. }
  141. $sql = "Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,description
  142. From dede_arctype where reid='$typeid' And ishidden<>1 order by sortrank asc limit 0,$row";
  143. //And id<>'$typeid'
  144. $dtp2 = new DedeTagParse();
  145. $dtp2->SetNameSpace("field","[","]");
  146. $dtp2->LoadSource($innertext);
  147. $dsql2->SetQuery($sql);
  148. $dsql2->Execute();
  149. $line = $row;
  150. for($i=0;$i < $line;$i++)
  151. {
  152. if($col>1) $likeType .= "<dl>\r\n";
  153. for($j=0;$j<$col;$j++)
  154. {
  155. if($col>1) $likeType .= "<dd>\r\n";
  156. if($row=$dsql2->GetArray())
  157. {
  158. $row['typelink'] = $row['typeurl'] = GetOneTypeUrlA($row);
  159. if(is_array($dtp2->CTags))
  160. {
  161. foreach($dtp2->CTags as $tagid=>$ctag){
  162. if(isset($row[$ctag->GetName()]))
  163. {
  164. $dtp2->Assign($tagid,$row[$ctag->GetName()]);
  165. }
  166. elseif (preg_match('/^sonchannel[0-9]*$/',$ctag->GetName()))
  167. {
  168. $dtp2->Assign($tagid,lib_channel_son($ctag,$row['id'],$dsql3));
  169. }
  170. }
  171. }
  172. $likeType .= $dtp2->GetResult();
  173. }
  174. if($col>1) $likeType .= "</dd>\r\n";
  175. }//Loop Col
  176. if($col>1)
  177. {
  178. $i += $col - 1;
  179. $likeType .= " </dl>\r\n";
  180. }
  181. }//Loop for $i
  182. reset($dsql3);
  183. $dsql2->FreeResult();
  184. return $likeType;
  185. }
  186. ?>
复制代码




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}
复制代码

发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;

如何回报帮助你解决问题的坛友,好办法就是点击帖子下方的评分按钮给对方加【金币】不会扣除自己的积分,做一个热心并受欢迎的人!

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则 需要先绑定手机号

关闭

站长推荐上一条 /1 下一条

QQ|侵权投诉|广告报价|手机版|小黑屋|西部数码代理|飘仙建站论坛 ( 豫ICP备2022021143号-1 )

GMT+8, 2024-5-9 00:51 , Processed in 0.037453 second(s), 9 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表