Display thumbnail only on the very first post in the loop?

  • add a variable before the loop (before the while), for example $first = true;
  • add a check inside the loop for this variable
  • after the use, change the flag

Code:

<!-- Start the Loop. -->
 <?php $first = true; ?>
 <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
 <!-- Display the Title as a link to the Post's permalink. -->
 <h2><a href="https://wordpress.stackexchange.com/questions/13020/<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<!-- Display the posts Image thumbnail for the post -->
    <?php if ( $first ): ?>
      <?php the_post_thumbnail();?>
      <?php $first = false; ?>
    <?php endif; ?>
 <!-- Display the date and a link to other posts by this posts author. -->
 <small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small>
 <!-- Display the Post's Content in a div box. -->
 <div class="entry">
   <?php the_content(); ?>
 </div>

Leave a Comment