• 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(); ?>`

  • The topic ‘Display/Show category name once.’ is closed to new replies.