【发布时间】:2017-12-13 17:30:01
【问题描述】:
我想在网格中显示我的帖子,父类别与子类别分开显示,如下所示:
PARENT CATEGORY
Post Title
SUB/CHILD CATEGORY
目前我正在使用此代码:
<?php while ( have_posts() ) : the_post(); ?>
<a href="<?php the_permalink();?>" class="col col-sm-6 col-md-4 clearfix single-resource mix all <?php $category = get_the_category(); $secondCategory = $category[1]->cat_name; echo str_replace(' ', '', $secondCategory); ?> " data-ref="mixitup-target">
<article class="resource-container">
<div class="image"><?php the_post_thumbnail( 'medium' ); ?></div>
<div class="details">
<span class="cat">
<?php $category = get_the_category();
$firstCategory = $category[0]->cat_name; echo $firstCategory;?> </span>
<h2><?php the_title();?></h2>
<span class="cat-sub"><?php $category = get_the_category(); $secondCategory = $category[1]->cat_name; echo $secondCategory;?></span>
</div>
</article>
</a>
<?php endwhile; ?>
但这似乎不一致,因为有时父母出现在孩子应该出现的地方,反之亦然。
我怎样才能让帖子显示在正确的位置,或者希望单独调用父类别和子类别?子类别也需要作为类添加到容器中。
【问题讨论】:
标签: php wordpress categories