DTCMS自定义标签,获取所有栏目以及获得二级子栏目导航
转载,侵删:https://www.cnblogs.com/qigege/p/4947793.html
取得二级栏目
DTcms.Web.UI\Label\category.cs中
get_category_child_list
返回当前所有子栏目
DTcms.Web.UI\Label\category.cs中,添加get_category_list的重载方法
/// <summary> /// 返回类别列表 /// </summary> /// <param name="parent_id">父类别ID</param>
/// <param name="channel_id">频道ID</param> /// <returns>DataTable</returns> protected DataTable get_category_list(int parent_id, string channel_id) { return new BLL.article_category().GetList(parent_id, int.Parse(channel_id)); }
需要注意的参数为string类型的,转化为int型的就可以
<ul id="navigation"> <li><a href="<%linkurl("index")%>">网站首页</a></li> <%set DataTable categorylist=get_category()%> <%loop category categorylist%> <li onmouseover="displaySubMenu(this)" onmouseout="hideSubMenu(this)"> <a href="/{category[name]}_index.html">{category[title]}</a> <ul> <%set DataTable arc_categorylist=get_category_list(0,{category[id]})%> <%loop arc_category arc_categorylist%> <li> <a href="/{category[name]}/list-{arc_category[id]}.html">{arc_category[title]}</a></li> <%/loop%> </ul> </li> <%/loop%> </ul>
链接地址看后台设置,灵活调用
<script type="text/javascript"> function displaySubMenu(li) { var subMenu = li.getElementsByTagName("ul")[0]; subMenu.style.display = "block"; } function hideSubMenu(li) { var subMenu = li.getElementsByTagName("ul")[0]; subMenu.style.display = "none"; } </script>
最终效果