开发者

Show Children Categories Only When Parent is Selected (Wordpress/Thesis Theme)

I am trying to create a category based navigation that is dependant on the parent selected.

For example, I would like to show sub-categories ONLY when the parent is selected and ONLY show the sub categories. I have tried a million things and no dice.

Just to be thorough here is my example:

Parent A Parent B Sub-Cat of Parent B Sub-Cat-2 of Parent B Sub-Cat-3 of Parent B

At first only Parent A and Parent B are shown. If I click Parent B all I will see is the 3 sub categories of Parent B and nothing else.

It's basically just conditional navigation with ca开发者_如何学运维tegories. I have done this before with Pages but categories are proving themselves to be a bitch for me. Any help would be greatly appreciated.


Have you tried get_categories

$parent_cat_id = 'your parent category id';

$args = array(
'type'                     => 'post',
'child_of'                 => $parent_cat_id,
'parent'                   => '',
'orderby'                  => 'name',
'order'                    => 'ASC',
'hide_empty'               => 1,
'hierarchical'             => 1,
'exclude'                  => '',
'include'                  =>'' ,
'number'                   =>'',
'taxonomy'                 => 'category',
'pad_counts'               => false );




        $categories = get_categories($args);
        echo "<pre>";
        print_r($categories);
        echo "<pre>";


I actually blogged about this a while ago :) Hope this helps :)

http://www.themer.me/blog/wordpress/33/how-to-display-sub-categories-depending-on-what-category-youre-in

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜