$list = $m->query(“select t.term_id,t.description,t.parent,c.*,t.count,t.term_taxonomy_id from wp_term_taxonomy as t inner join wp_terms as c on t.term_id = c.term_id where t.taxonomy =’category’ and t.parent = 0 order by t.parent asc”);//获取父栏目
foreach($list as $key=>$val){
foreach($val as $key2=>$val2){
if($key2==”term_id”){
//dump($val2);
$list2 = $m->query(“select t.term_id,t.description,t.parent,c.*,t.count,t.term_taxonomy_id from wp_term_taxonomy as t inner join wp_terms as c on t.term_id = c.term_id where t.taxonomy =’category’ and t.parent = ‘$val2’ order by t.parent asc”);//获取子栏目
foreach($list2 as $keyf=>$valf){
foreach($valf as $keyf2=>$valf2){
$list[$key][‘zi’][$keyf][$keyf2] = $valf2;
}
}
}
}
}
模板上再对$list做相应处理:
<ul data-role=”listview” data-inset=”true” data-filter=”true”>
<{foreach from=$list item=vo}>
<li data-theme=”b”><a href=”__URL__/article_list/cid/<{$vo.term_taxonomy_id}>” data-transition=”pop”><h3><{$vo.name}></h3>
<p> <{$vo.description}></p>
</a>
<span class=”ui-li-count”><{$vo.count}></span>
</li>
<{if $vo.zi}>
<{foreach from=$vo.zi item=vof}>
<li data-theme=”c”><a href=”__URL__/article_list/cid/<{$vof.term_taxonomy_id}>” data-transition=”pop”><h3><{$vof.name}></h3>
<p> <{$vof.description}></p>
</a>
<span class=”ui-li-count”><{$vof.count}></span>
</li>
<{/foreach}>
<{/if}>
<{/foreach}>