<div class="careerleft">
<?php query_posts('cat=9&paged='.get_query_var('paged')); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<p class="career">"><?php the_title(); ?></p>
<p>Category: <?php single_cat_title()?></p>
<p>Date posted:<?php the_time('F j, Y') ?></p>
</div>
<?php endwhile; ?>
<?php else : ?>
<h2>Not Found</h2>
<?php endif; ?>
</div>我想显示子类别名称,但当我使用时,它只显示父类别名称。在我的类别中,父类别名称是"careers",这个类别有3个子类别名称,分别是管理、IT相关和会计。显示子类别名称的代码是什么?
发布于 2013-03-18 21:42:14
在这里,您必须首先提取子类别。请参阅如何提取Wordpress Categories。
提取父类别的所有类别
<?php $args = array( 'type' => 'post', 'parent' => 9, 'taxonomy' => 'category' );?>
<?php $categories = get_categories( $args ); ?>
提取所有类别后,创建aloop以打印它们
https://stackoverflow.com/questions/12613710
复制相似问题