<if condition="count($ct['child']) gt 0">
<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown"> {$ct.ti
<ul class="dropdown-menu open">
<volist name="ct['child']" id="vs">
<li><a href="{:U('/home/article/lists/category/'.$vs[id])}">{$vs.ti
</volist>
</ul>
</li>
<else />
<li ><a href="{:U('/home/article/lists/category/'.$ct[id])}" > {$ct.ti
</if>
</Think:mycate>
记住返回的数据必须是多维数组,
count($ct['child']) gt 0 判断child的属猪是否大于0
一下代码放到 function.php里
//用途 递归分类
function dd($cate,$name="child",$pid=0){
$arr=array();
foreach($cate as $v){
if($v["pid"]==$pid){
$v[$name]=dd($cate,$name,$v["id"]);
$arr[]=$v;
}
}
return $arr;
}
下TagLib下的think.php里定义标签。
'mycate' => array('attr'=>'id,name','close' => 1),
添加function
public function _mycate($tag, $content){
$parse='<?php ';
$parse .='$cate= M(\'category\')->select();';
$parse.='$__CL__=dd($cate,$name=\'child\',$pid=0);';
$parse.='($__CL__);';
$parse .= '?>';
//dump($parse);
$parse.='<volist name="__CL__" id="'. $tag['name'] .'"> ';
$parse.=$content;
$parse.='</volist>';
return $parse;
}
不多说 慢慢摸索吧
最佳答案
