如何检查类别是否为父类别

时间:2012-07-04 06:55:15

标签: php wordpress

我怎么可能这样做?另外我如何显示其子类别?

1 个答案:

答案 0 :(得分:7)

检查

<?php $this_category = get_category($cat); ?>
<!-- If category is parent, list it -->
<?php if ($this_category->category_parent == 0) { ?>

<?php } else { ?>
<!-- If category is not parent, list parent category -->
<?php $parent_category = get_category($this_category->category_parent); ?>


<?php } ?>