2012-01-26 269 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 
?> 

確保在帖子本身中,子類別被選中但不是父類別。
(有時如果兩者都被「檢查」,它不起作用)

相關問題