Monday, April 18, 2016

Display category name only once inside loop

I have been researching on how I can output the category name on a wordpress loop for custom post only to display only once. If there are any posts under the same category, the category name will not be display only the first one. I tried searching the codex for "the_category" but there wasn't anything there that could help me with my problem. Here is the sample of the code I have been working.

<?php $film_timeline = new WP_Query( array('post_type' => 'film_timeline') ); if ( $film_timeline->have_posts() ) : while ( $film_timeline->have_posts() ) : $film_timeline->the_post(); ?> <h3 class="category-name"><?php the_category(); ?></h3> <?php wp_reset_postdata(); ?> <?php endwhile; else: ?> <?php //Insert Error Message ?> <?php endif; ?> <?php wp_reset_query(); ?>
Source: Display category name only once inside loop

No comments:

Post a Comment