1.方法
//递归函数 实现无限级分类列表 function get_cate_list($list,$pid=0,$level=0) { static $tree = array(); foreach($list as $row) { if($row['pid']==$pid) { $row['level'] = $level; $tree[] = $row; get_cate_list($list, $row['id'], $level + 1); } } return $tree; }
在前端如何展示出来
<div class="menu_dropdown bk_2"> {foreach $nav as $k => $nav_one} {foreach $nav_one['son'] as $kk=>$nav_two} <dl id="menu{$kk}" class="sec_nav" data-pid="{$nav_one.id}" style="{if($nav_one.id == $current_auth_ids[1])}display:block;{else/}display:none;{/if}"> <dt class="{if($nav_two.id == $current_auth_ids[2])}selected{/if}"><i class="Hui-iconfont"></i> {$nav_two.auth_name}<i class="Hui-iconfont menu_dropdown-arrow"></i></dt> <dd style="{if($nav_two.id == $current_auth_ids[2])}display:block;{/if}"> <ul> {foreach $nav_two['son'] as $nav_three} <li data-id="{$nav_three.id}" class="{if($nav_three.id == $current_auth_ids[3])}current{/if}"> <a href="{if($nav_three['auth_c']&&$nav_three['auth_a'])}{:url($nav_three['auth_c'] . '/' . $nav_three['auth_a'])}{else/}javascript:;{/if}" title="">{$nav_three.auth_name}</a> </li> {/foreach} </ul> </dd> </dl> {/foreach} {/foreach} </div>
效果图如下