Wordpress显示类别的子类别

时间:2012-02-12 10:32:53

标签: wordpress categories

是否可以在Wordpress中显示类别的子类别?

我们说我有A类和B类。在A中我有A1,A2和A3。在B B1和B2。 现在我想在前端展示类别......类似于:

Category A:
- A1
- A2
- A3
Category B:
- B1
- B2

这在Wordpress中是否可以轻松实现?如果是,怎么样?

由于

4 个答案:

答案 0 :(得分:2)

是的,可以在主题设置中传递给nav_menu函数的深度参数。

http://codex.wordpress.org/Function_Reference/wp_nav_menu

答案 1 :(得分:1)

简单搜索'子类别'在wordpress.org插件区域返回了很多例子。

http://wordpress.org/extend/plugins/search.php?q=subcategories

答案 2 :(得分:0)

1)在任何类别页面上显示子类别:

<?php
if (is_category())
{
$cur_cat = get_query_var('cat');
    if ($cur_cat) 
    {
        $new_cats = wp_list_categories('echo=false&child_of=' . $cur_cat . '&depth=1&title_li=&&show_count=1&hide_empty=0');
        echo '<ul>' . $new_cats . '</ul>';
    }
}
?>

2)显示所有热门分类:

<?php wp_list_categories('depth=1&title_li=&exclude=1&show_count=1&hide_empty=0'); ?> 

3)显示所有顶级类别+子类别,如树状菜单:

Use FoCal plugin. 

4)另外,试试这段代码:

http://wpworks.wordpress.com/2011/01/13/displaying-categories-and-subcategories-tree-on-wordpress/

答案 3 :(得分:0)

在Wordpress中的Woocommerece下拉列表中显示类别和子类别

   <option value=''>All</option>

get_results($ SQL);     foreach($ allfilters as $ singlefilter){

    ?>
 <option value="<?php echo $singlefilter->slug;?>" "<?php if($singlefilter->slug == $singlefilter->name) echo 'selected'; ?>"> <?php echo $singlefilter->name;?></option>;

<?php }

&GT?;    

相关问题