1

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(); ?>
  • How many times did you got if it't not once? Btw, you should add the h3 close tag to your code. – MinhTri Apr 19 '16 at 5:10
  • Sorry what do you mean when you said "How many times did you got if it't not once?" – clestcruz Apr 19 '16 at 5:23
  • I meant once for what? Once for each category or once for a list of different categories? – MinhTri Apr 19 '16 at 5:25
  • ah ok, once for a list of different categories. – clestcruz Apr 19 '16 at 5:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.