最新公告
  • 欢迎您光临仿站吧 帝国CMS模板一站式建站供应平台 . 欢迎加入VIP
  • 织梦CMS 动态导航下拉菜单的代码实例

    正文概述 仿站吧   2022-02-26 15:36:04  

    动态导航下拉菜单的代码实例

    1、修改include/taglib文件夹中的channel.lib.php文件,替换为如下内容:

    1. <?php
    2. /**
    3. * 动态导航下拉菜单
    4. * Edit www.zuimoban.com
    5. * Date 2015-5-3
    6. */
    7. function lib_channel(&$ctag,&$refObj)
    8. {
    9. global $_sys_globals,$envs,$dsql;
    10. $attlist = "typeid|0,reid|0,row|100,col|1,type|son,currentstyle|";
    11. FillAttsDefault($ctag->CAttribute->Items,$attlist);
    12. extract($ctag->CAttribute->Items, EXTR_SKIP);
    13. $innertext = $ctag->GetInnerText();
    14. if(empty($typeid) && $envs['typeid']!=0)
    15. {
    16. $typeid = $envs['typeid'];
    17. $reid = $envs['reid'];
    18. }else{
    19. $reid=0;
    20. }
    21. if($type==''||$type=='sun') $type="son";
    22. if($innertext=='') $innertext = GetSysTemplets("channel_list.htm");
    23. if($reid==0 && $typeid>0)
    24. {
    25. $dbrow = $dsql->GetOne("Select reid From <a href="mailto:`dede_arctype">`dede_arctype</a>` where id='$typeid' ");
    26. if(is_array($dbrow)) $reid = $dbrow['reid'];
    27. }
    28. $likeType = '';
    29. if($type=='top')
    30. {
    31. $sql = "Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,description
    32. From <a href="mailto:`dede_arctype">`dede_arctype</a>` where reid=0 And ishidden<>1 order by sortrank asc limit 0,$row";
    33. }
    34. else if($type=="son")
    35. {
    36. //if($_sys_globals['typeid']>0) $typeid = $_sys_globals['typeid'];
    37. if($typeid==0) {
    38. return '';
    39. }
    40. $sql = "Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,description
    41. From <a href="mailto:`dede_arctype">`dede_arctype</a>` where reid='$typeid' And ishidden<>1 order by sortrank asc limit 0,$row";
    42. }
    43. else if($type=="self")
    44. {
    45. if($reid==0) {
    46. return '';
    47. }
    48. $sql = "Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,description
    49. From <a href="mailto:`dede_arctype">`dede_arctype</a>` where reid='$reid' And ishidden<>1 order by sortrank asc limit 0,$row";
    50. }
    51. //And id<>'$typeid'
    52. $dtp2 = new DedeTagParse();
    53. $dtp2->SetNameSpace("field","[","]");
    54. $dtp2->LoadSource($innertext);
    55. $dsql2 = clone $dsql;
    56. $dsql->SetQuery($sql);
    57. $dsql->Execute();
    58. $line = $row;
    59. $GLOBALS['autoindex'] = 0;
    60. for($i=0;$i < $line;$i++)
    61. {
    62. if($col>1) $likeType .= "<dl>\r\n";
    63. for($j=0;$j<$col;$j++)
    64. {
    65. if($col>1) $likeType .= "<dd>\r\n";
    66. if($row=$dsql->GetArray())
    67. {
    68. if($type=='self' && $row['id']==$typeid) //处理同级栏目中,当前栏目的样式
    69. {
    70. if($currentstyle!='')
    71. {
    72. $linkOkstr = $currentstyle;
    73. $row['typelink'] = GetOneTypeUrlA($row);
    74. $linkOkstr = str_replace("~typelink~",$row['typelink'],$linkOkstr);
    75. $linkOkstr = str_replace("~typename~",$row['typename'],$linkOkstr);
    76. $likeType .= $linkOkstr;
    77. }
    78. }else
    79. {
    80. $row['typelink'] = $row['typeurl'] = GetOneTypeUrlA($row);
    81. if(is_array($dtp2->CTags))
    82. {
    83. foreach($dtp2->CTags as $tagid=>$ctag){
    84. if(isset($row[$ctag->GetName()]))
    85. {
    86. $dtp2->Assign($tagid,$row[$ctag->GetName()]);
    87. }
    88. elseif (preg_match('/^sonchannel[0-9]*$/',$ctag->GetName()))
    89. {
    90. $dtp2->Assign($tagid,lib_channel_son($ctag,$row['id'],$dsql2));
    91. }
    92. }
    93. }
    94. $likeType .= $dtp2->GetResult();
    95. }
    96. }
    97. if($col>1) $likeType .= "</dd>\r\n";
    98. $GLOBALS['autoindex']++;
    99. }//Loop Col
    100. if($col>1)
    101. {
    102. $i += $col - 1;
    103. $likeType .= " </dl>\r\n";
    104. }
    105. }//Loop for $i
    106. reset($dsql2);
    107. $dsql->FreeResult();
    108. return $likeType;
    109. }
    110. function lib_channel_son($ctag,$typeid = 0,$dsql2)
    111. {
    112. $attlist = "row|100,col|1,currentstyle|";
    113. FillAttsDefault($ctag->CAttribute->Items,$attlist);
    114. extract($ctag->CAttribute->Items, EXTR_SKIP);
    115. $innertext = $ctag->GetInnerText();
    116. $dsql3 = clone $dsql2;
    117. $likeType = '';
    118. //if($_sys_globals['typeid']>0) $typeid = $_sys_globals['typeid'];
    119. if($typeid==0) {
    120. return '';
    121. }
    122. $sql = "Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,description
    123. From <a href="mailto:`dede_arctype">`dede_arctype</a>` where reid='$typeid' And ishidden<>1 order by sortrank asc limit 0,$row";
    124. //And id<>'$typeid'
    125. $dtp2 = new DedeTagParse();
    126. $dtp2->SetNameSpace("field","[","]");
    127. $dtp2->LoadSource($innertext);
    128. $dsql2->SetQuery($sql);
    129. $dsql2->Execute();
    130. $line = $row;
    131. for($i=0;$i < $line;$i++)
    132. {
    133. if($col>1) $likeType .= "<dl>\r\n";
    134. for($j=0;$j<$col;$j++)
    135. {
    136. if($col>1) $likeType .= "<dd>\r\n";
    137. if($row=$dsql2->GetArray())
    138. {
    139. $row['typelink'] = $row['typeurl'] = GetOneTypeUrlA($row);
    140. if(is_array($dtp2->CTags))
    141. {
    142. foreach($dtp2->CTags as $tagid=>$ctag){
    143. if(isset($row[$ctag->GetName()]))
    144. {
    145. $dtp2->Assign($tagid,$row[$ctag->GetName()]);
    146. }
    147. elseif (preg_match('/^sonchannel[0-9]*$/',$ctag->GetName()))
    148. {
    149. $dtp2->Assign($tagid,lib_channel_son($ctag,$row['id'],$dsql3));
    150. }
    151. }
    152. }
    153. $likeType .= $dtp2->GetResult();
    154. }
    155. if($col>1) $likeType .= "</dd>\r\n";
    156. }//Loop Col
    157. if($col>1)
    158. {
    159. $i += $col - 1;
    160. $likeType .= " </dl>\r\n";
    161. }
    162. }//Loop for $i
    163. reset($dsql3);
    164. $dsql2->FreeResult();
    165. return $likeType;
    166. }
    167. ?>
    168. 2、调用示例
    169. {dede:channel typeid='1'}
    170. <li>
    171. <a class="" href="[field:typeurl/]" title="">[field:typename/]
    172. <img src="***.gif" /></a>
    173. <div class="sub">
    174. <ul>
    175. [field:sonchannel0]<li><a href="[field:typeurl/]">[field:typename/]</a></li>[/field:sonchannel0]
    176. </ul>
    177. </div>
    178. </li>
    179. {/dede:channel}
    仿站吧,一个优质的源码资源平台!
    仿站吧 » 织梦CMS 动态导航下拉菜单的代码实例