wordpressで、子タームの記事一覧ページを作成したいです。
現在、「category」というタクソノミーをCPT UIで作成し、
親タームに「親カテゴリー」子タームにそれぞれ、子カテゴリー、子カテゴリー2というものを作成しました。
画像1参照
画像2のように、それぞれの子タームのタイトルと記事をひとまとまりにリスト化して出したいです。
どのようにすればよいでしょうか?
<?php if (have_posts()): ?> <?php while (have_posts()) : the_post(); ?> <h3> <?php $terms = get_the_terms( $post->ID, 'category' ); foreach ( $terms as $term ) { if ( $term->parent ) { echo $term->name; } } ?> </h3> <div class="row"> <article class="col-md-4"> <div class="post-thumbnail"> <?php if (has_post_thumbnail()) : ?> <?php the_post_thumbnail('full'); ?> <?php else : ?> <img src="<?php bloginfo('template_url'); ?>/images/no-image.jpg" alt="<?php the_title(); ?>"> <?php endif ; ?> </div> <h4> <?php the_title(); ?> </h4> </article> </div> <?php endwhile; ?> <?php else: ?> <?php endif; ?>
上記のコードで試してみると、やはりタイトルも含めてループするので、上手くいきません。
ご教授の程よろしくお願いいたします。
あなたの回答
tips
プレビュー