Show code only for first query

We are working on a site where the first query on archive is displayed featured.

<?php
  $firstonly = 0; // Set the variable to 0 so we can check for it later.
  if ( have_posts() ) : while ( have_posts() ) : the_post();
?>

  <h2><?php the_title(); ?></h2>
  <?php
    if ($firstonly < 1) { // Check if it's been displayed
      echo "Show only on First";
      $firstExcerpt++; // Changes the variable so that next time, it won't show
    };
  ?>

<?php endwhile; endif; ?>

Leave a Reply

Your email address will not be published. Required fields are marked *