【发布时间】:2015-06-26 10:52:37
【问题描述】:
我正在遍历所有帖子,并尝试输出与每个帖子相关的类别 nicename。因此,如果有类别 A、B 和 C 且帖子 X 仅与类别 A 和 C 相关联,那么我只想输出类别 A 和 C 的 nicename。
这是循环:
<?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; ?>
【问题讨论】: