欢迎光临景诺科技软件开发淘宝店

进店请收藏,谢谢

wordpress获取栏目子分类sql

$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}>

更多

本文固定链接: http://shanmao.me/web-system/wordpress/wordpress-huo-qu-lan-mu-zi-fen-lei-sql | 山猫的博客

该日志由 admin 于2013年06月02日发表在 wordpress 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: wordpress获取栏目子分类sql | 山猫的博客
关键字: