2012-01-26 274 views
1

我有主类别 - 次类别1 - 次类别2 - 儿童类别。如何在wordpress中显示帖子的子类别名称?

如果我点击子类别,使用以下脚本我可以对帖子进行排序。

<?php if (have_posts()) : $i = 0; while (have_posts()) : $i++; the_post(); ?>

为了显示我使用的类别名称,

$category = get_the_category();$category->cat_name;

但我不能显示其子类别和子类别,请帮助我!

回答

0
<?php while (have_posts()) : the_post(); 
    $category = get_the_category(); 
    //var_export($category[0]); // All info about this post's category 
    echo $category[0]->cat_name; // will print the category/sub-category name 
?> 

确保在帖子本身中,子类别被选中但不是父类别。
(有时如果两者都被“检查”,它不起作用)

相关问题