2013-04-04 24 views
0

如果用户正在浏览的当前类别是特定顶级类别的descedant我要显示的类别的特定列表:如何确定类别ID是顶级父类的后裔

我知道我可以用这个代码获得当前分类ID:

$cat = get_query_var('cat'); 

但我怎么能检查该类别ID是一个特定的顶级父类的后代:

<?php if (.....) { ?> 
     <?php wp_list_categories('orderby=id&show_count=0&use_desc_for_title=0&child_of='.$men->term_id); ?> 
         <?php } ?> 

回答

0

您可以ü请输入category_parent属性以获取父级的ID,然后使用get_the_category()函数加载它,或者确定它是否是您想要的。对于多个级别,您需要使用递归。

$category_id = get_query_var('cat'); 
$category = get_the_category($category_id); 
$parent_id = $category[0]->category_parent; 
$parent  = get_the_category($parent_id); 
+0

** get_category **而不是** get_the_category ** – 2015-01-23 11:33:35