张你好11 发布于:2021-11-30 02:33:08
CMS无法显示三级栏目信息内容
CMS显示二级栏目
显示二级栏目列表通常使用 foreach 循环顶级栏目菜单,判断是否有子栏目(二级栏目),有则继续循环输出
三级栏目按照逻辑来说 以此类推是可以的
显示二级栏目:
<ul class="snv a"> {foreach $classtypedata as $v} {if($v['isshow']==1)} {if($v[pid]==0)} <li> <div class="con"> <a href="{$v[url]}" class="tit">{$v['classname']}</a> {if($v[haschild])} <ul class="subsnv"> {foreach $v['children']['list'] as $vv} {if($vv['isshow']==1)} <li> <div class="con"> <a href="{$vv[url]}" class="tit">{$vv['classname']}</a> </div> </li> {/if} {/foreach} </ul> {/if} </div> </li> {/if} {/if} {/foreach} </ul>
以此类推即可显示三级栏目
显示三级栏目:
<ul class="snv a"> {foreach $classtypedata as $v} {if($v['isshow']==1)} {if($v[pid]==0)} <li> <div class="con"> <a href="{$v[url]}" class="tit">{$v['classname']}</a> {if($v[haschild])} <ul class="subsnv"> {foreach $v['children']['list'] as $vv} {if($vv['isshow']==1)} <li> <div class="con"> <a href="{$vv[url]}" class="tit">{$vv['classname']}</a> {if($vv[haschild])} <ul class="subsnv smsub"> {foreach $vv['children']['list'] as $vvv} {if($vvv['isshow']==1)} <li> <div class="con"> <a href="{$vvv['url']}" class="tit">{$vvv['classname']}</a> </div> </li> {/if} {/foreach} </ul> {/if} </div> </li> {/if} {/foreach} </ul> {/if} </div> </li> {/if} {/if} {/foreach} </ul>
但是此处会出现问题:
{$vv['children']['list']} 没有内容(为空)显示不出来数据
解决方案:
$vv['children']['list'] 改为 ↓↓↓↓ $classtypedata [$vv['id']]['children']['list']
原因:
之所以三级以上children 没有数据,是因为三级以上很多栏目会给这个递归带来很大的数据压力
完整代码 :
<ul class="snv a"> {foreach $classtypedata as $v} {if($v['isshow']==1)} {if($v[pid]==0)} <li> <div class="con"> <a href="{$v[url]}" class="tit">{$v['classname']}</a> {if($v[haschild])} <ul class="subsnv"> {foreach $v['children']['list'] as $vv} {if($vv['isshow']==1)} <li> <div class="con"> <a href="{$vv[url]}" class="tit">{$vv['classname']}</a> {if($vv[haschild])} <ul class="subsnv smsub"> {foreach $classtypedata [$vv['id']]['children']['list'] as $vvv} {if($vvv['isshow']==1)} <li> <div class="con"> <a href="{$vvv['url']}" class="tit">{$vvv['classname']}</a> </div> </li> {/if} {/foreach} </ul> {/if} </div> </li> {/if} {/foreach} </ul> {/if} </div> </li> {/if} {/if} {/foreach} </ul>
登录后可以留言提问!
微信扫码登录