请选择 进入手机版 | 继续访问电脑版
  • 设为首页
  • 收藏本站
  • 桌面快捷
  • 手机版
  • 微信
    站长微信 搜索微信号:
    q515138
  • 快捷导航

    织梦Dede实现嵌套获取栏目及其子栏目列表

    [复制链接]
    作者: 网站医生(新手上路) | 丢币: 0 (丢币充值 | 升级VIP) | 查看: 47| 回复: 1| 发表于 2019-10-4 20:00:24 | 显示全部楼层 |阅读模式
    织梦Dede实现嵌套获取栏目及其子栏目列表
    因为时间仓促可能有些不成熟 这里只是抛砖引玉了
    修改 channerl.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. if(empty($typeid) && $envs['typeid']!=0)
    10. {
    11. $typeid = $envs['typeid'];
    12. $reid = $envs['reid'];
    13. }else{
    14. $reid=0;
    15. }

    16. if($type==''||$type=='sun') $type="son";
    17. if($innertext=='') $innertext = GetSysTemplets("channel_list.htm");

    18. if($reid==0 && $typeid>0)
    19. {
    20. $dbrow = $dsql->GetOne("Select reid From dede_arctype where id='$typeid' ");
    21. if(is_array($dbrow)) $reid = $dbrow['reid'];
    22. }

    23. $likeType = '';
    24. if($type=='top')
    25. {
    26. $sql = "Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,description
    27. From dede_arctype where reid=0 And ishidden<>1 order by sortrank asc limit 0,$row";
    28. }
    29. else if($type=="son")
    30. {
    31. //if($_sys_globals['typeid']>0) $typeid = $_sys_globals['typeid'];
    32. if($typeid==0) {
    33. return '';
    34. }
    35. $sql = "Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,description
    36. From dede_arctype where reid='$typeid' And ishidden<>1 order by sortrank asc limit 0,$row";
    37. }
    38. else if($type=="self")
    39. {
    40. if($reid==0) {
    41. return '';
    42. }
    43. $sql = "Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,description
    44. From `dede_arctype` where reid='$reid' And ishidden<>1 order by sortrank asc limit 0,$row";
    45. }
    46. //And id<>'$typeid'
    47. $dtp2 = new DedeTagParse();
    48. $dtp2->SetNameSpace("field","[","]");
    49. $dtp2->LoadSource($innertext);
    50. $dsql2 = clone $dsql;
    51. $dsql->SetQuery($sql);
    52. $dsql->Execute();

    53. $line = $row;
    54. $GLOBALS['autoindex'] = 0;
    55. for($i=0;$i < $line;$i++)
    56. {
    57. if($col>1) $likeType .= "<dl>\r\n";
    58. for($j=0;$j<$col;$j++)
    59. {
    60. if($col>1) $likeType .= "<dd>\r\n";
    61. if($row=$dsql->GetArray())
    62. {
    63. if($type=='self' && $row['id']==$typeid) //处理同级栏目中,当前栏目的样式
    64. {
    65. if($currentstyle!='')
    66. {
    67. $linkOkstr = $currentstyle;
    68. $row['typelink'] = GetOneTypeUrlA($row);
    69. $linkOkstr = str_replace("~typelink~",$row['typelink'],$linkOkstr);
    70. $linkOkstr = str_replace("~typename~",$row['typename'],$linkOkstr);
    71. $likeType .= $linkOkstr;
    72. }
    73. }else
    74. {
    75. $row['typelink'] = $row['typeurl'] = GetOneTypeUrlA($row);
    76. if(is_array($dtp2->CTags))
    77. {
    78. foreach($dtp2->CTags as $tagid=>$ctag){
    79. if(isset($row[$ctag->GetName()]))
    80. {
    81. $dtp2->Assign($tagid,$row[$ctag->GetName()]);
    82. }
    83. elseif ('sonchannel' == $ctag->GetName())
    84. {
    85. $dtp2->Assign($tagid,lib_channel_son($ctag,$row['id'],$dsql2));
    86. }
    87. }
    88. }
    89. $likeType .= $dtp2->GetResult();
    90. }
    91. }
    92. if($col>1) $likeType .= "</dd>\r\n";
    93. $GLOBALS['autoindex']++;
    94. }//Loop Col
    95. if($col>1)
    96. {
    97. $i += $col - 1;
    98. $likeType .= " </dl>\r\n";
    99. }
    100. }//Loop for $i

    101. $dsql->FreeResult();
    102. return $likeType;
    103. }
    104. function lib_channel_son($ctag,$typeid = 0,$dsql2)
    105. {
    106. $attlist = "row|100,col|1,currentstyle|";
    107. FillAttsDefault($ctag->CAttribute->Items,$attlist);
    108. extract($ctag->CAttribute->Items, EXTR_SKIP);
    109. $innertext = $ctag->GetInnerText();

    110. $likeType = '';

    111. //if($_sys_globals['typeid']>0) $typeid = $_sys_globals['typeid'];
    112. if($typeid==0) {
    113. return '';
    114. }
    115. $sql = "Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,description
    116. From dede_arctype where reid='$typeid' And ishidden<>1 order by sortrank asc limit 0,$row";
    117. //And id<>'$typeid'
    118. $dtp2 = new DedeTagParse();
    119. $dtp2->SetNameSpace("field","[","]");
    120. $dtp2->LoadSource($innertext);
    121. $dsql2->SetQuery($sql);
    122. $dsql2->Execute();
    123. $line = $row;

    124. for($i=0;$i < $line;$i++)
    125. {
    126. if($col>1) $likeType .= "<dl>\r\n";
    127. for($j=0;$j<$col;$j++)
    128. {
    129. if($col>1) $likeType .= "<dd>\r\n";
    130. if($row=$dsql2->GetArray())
    131. {
    132. $row['typelink'] = $row['typeurl'] = GetOneTypeUrlA($row);
    133. if(is_array($dtp2->CTags))
    134. {
    135. foreach($dtp2->CTags as $tagid=>$ctag){
    136. if(isset($row[$ctag->GetName()]))
    137. {
    138. $dtp2->Assign($tagid,$row[$ctag->GetName()]);
    139. }
    140. elseif ('sonchannel' == $ctag->GetName())
    141. {
    142. $dtp2->Assign($tagid,lib_channel_son($ctag,$row['id'],$dsql2));
    143. }
    144. }
    145. }
    146. $likeType .= $dtp2->GetResult();
    147. }
    148. if($col>1) $likeType .= "</dd>\r\n";
    149. }//Loop Col
    150. if($col>1)
    151. {
    152. $i += $col - 1;
    153. $likeType .= " </dl>\r\n";
    154. }
    155. }//Loop for $i
    156. $dsql2->FreeResult();
    157. return $likeType;
    158. }
    159. ?>
    复制代码
    模板调用

    1. {dede:channel type='son' typeid='14'}
    2. <div><a href="[field:typelink/]">[field:typename/]</a></div>

    3. <ul>
    4. [field:sonchannel]
    5. <li><a href="[field:typelink/]">[field:typename/]</a></li>
    6. [/field:sonchannel]
    7. </ul>
    8. {/dede:channel}
    复制代码


    推荐给好友: [复制链接]
    楼主热帖
    回复

    使用道具 举报

    苹果(新手上路) | 丢币: 9 (丢币充值 | 升级VIP) | 查看: 47| 回复: 1| 发表于 2019-10-4 20:00:24 | 显示全部楼层
    技术学习教程网,支持一下。
    回复

    使用道具 举报

    网站地图/免责声明/Archiver/手机版/小黑屋/ZiDiu.Com ( 粤ICP备17166275号 )

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