基本使用
判断是否首页,输出高亮代码 <li><a class="a1 {if(!isset($type))}color{/if}" href="/">首页</a></li> {foreach $classtypedata as $v} 判断输出可显示的栏目 {if($v['isshow']==1)} 输出一级栏目 {if($v['pid']==0)} <li> 判断是否当前栏目,输出高亮代码 <a class="a1 {if(isset($type) && in_array($type['id'],$v['children']['ids']))}color{/if}" href="{$v['url']}">{$v['classname']}</a> 判断是否有下级,输出下级分类 {if($v['haschild'])} <ul> {foreach $v['children']['list'] as $vv} {if($vv['isshow']==1)} <li><a href="{$vv['url']}">{$vv['classname']}</a></li> {/if} {/foreach} </ul> {/if} </li> {/if} {/if} {/foreach}
特别提醒:如果要输出二级以上的子栏目,需要将上面的 $v['children'] 换成 $classtypedata[$v['id']]['children']
2.0+ 和 1.9.x 支持无限级,可以直接用 $v['children']
输出二级三级
{foreach $classtypedata as $v} {foreach $v['children']['list'] as $vv} {foreach $classtypedata[$vv['id']]['children']['list'] as $vvv} //三级以上输出,借助 $classtypedata来获取下级数据 {/foreach} {/foreach} {/foreach}
直接使用系统内置(系统配置中的栏目全局递归不能关闭,否则失效)
{foreach $classtypedata as $v} {foreach $v['children']['list'] as $vv} {foreach $vv['children']['list'] as $vvv} //三级递归有效,可以一直递归写下去 {/foreach} {/foreach} {/foreach}
使用loop输出栏目
{loop table="classtype" pid="0" isshow="1" as="v"} <li> 判断是否当前栏目,输出高亮代码 <a class="a1 {if(isset($type) && in_array($type['id'],$classtypedata[$v['id']]['children']['ids']))}color{/if}" href="{$v['url']}">{$v['classname']}</a> 判断是否有下级,输出下级分类 {if($classtypedata[$v['id']]['haschild'])} <ul> {foreach $classtypedata[$v['id']]['children']['list'] as $vv} <li><a href="{$vv['url']}">{$vv['classname']}</a></li> {/foreach} </ul> {/if} </li> {/loop}