• <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    I’m using the loop to pull posts, etc.. I have a header above the posts that I want to display only if there are posts.. and when there are no posts, don’t display the header at all.

    How would I break up the loop to throw something in the “if” so that the header displays if there are posts, then the while continues so the header doesn’t repeat for every post?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Try using something like this just after the line you showed:

    <?php if ( ++$show_hdr == 1 ) {
       // Show the header here
    } ?>

    example:

    <?php if ( have_posts() ) : ?>
    <h3>example html code for the title <?php echo 'what ever'; ?> and more</h3> <!--get the idea?-->
    <?php while ( have_posts() ) : the_post(); ?>
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Display Title Once if Loop has posts’ is closed to new replies.