1
我正在循環所有帖子,我試圖輸出與每個帖子相關的類別nicename。因此,如果有類別A,B和C,後X僅與類別A和C相關聯,那麼我只想輸出類別A和C的nicename。WordPress的 - 顯示在循環內與帖子ID相關聯的所有子類別
這裏的循環:
<?php $subs = new WP_Query(array('post_type' => 'case-study'));
if($subs->have_posts()) : while($subs->have_posts()) : $subs->the_post(); ?>
<?php the_title(); ?>
<p>Associated Child Categories</p>
//Show nicenames of each child category associated to each post
<?php $category = get_categories($post->ID);
foreach(($category) as $cats) { echo $category->category_nicename; }?>
<?php endwhile; endif; ?>
這是偉大的,雖然它的輸出父類別以及兒童。我如何排除父母? – egr103
已更新我的回答 – rnevius
很棒,感謝您的額外更新:-) – egr103