Title: Loop &#8211; first header tag
Last modified: August 24, 2016

---

# Loop – first header tag

 *  [Luke](https://wordpress.org/support/users/lukejongibson/)
 * (@lukejongibson)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/loop-first-header-tag/)
 * I only want the first header tag in the following code to be H1 and the following
   tags to be H2, I used to know how to do this, but I’ve complete forgotten. Can
   anyone point me in the right direction?
 * Thank you
 *     ```
       <?php
       	$args = array( 'post_type' => 'discussion', 'posts_per_page' => 1 );
       $loop = new WP_Query( $args );
       while ( $loop->have_posts() ) : $loop->the_post();
         echo '<div class="headline-discussion">';
         ?>
   
          <?php echo '<div class="headdisc-image">';
   
       if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
       	the_post_thumbnail();
       }
         echo '</div>';
   
         ?>
   
            <div class="post">
   
       				<h1 class="toptitle"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1>
   
       			<div class="entry">
       				<?php the_excerpt(); ?>
       			</div>
       		</div>
   
         </div>
         <?php
       endwhile; ?>
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Cindy Cullen](https://wordpress.org/support/users/cgcullen/)
 * (@cgcullen)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/loop-first-header-tag/#post-6022066)
 * This might work:
 * `if( $wp_query->current_post == 0 && !is_paged() ) { /*first post*/ }`
 * Taken from [this post](https://wordpress.org/support/topic/target-first-post-in-loop?replies=5)
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/loop-first-header-tag/#post-6022101)
 * based on _[@cindy](https://wordpress.org/support/users/cindy/) Cullen_‘s reply,
   and adapted to your custom query, try to replace this line:
 *     ```
       <h1 class="toptitle"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1>
       ```
   
 * with (using a [ternary operator](http://php.net/manual/en/language.operators.comparison.php)):
 *     ```
       <<?php echo ( $loop->current_post == 0 ? 'h1' : 'h2' ); ?> class="toptitle"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1>
       ```
   
 *  Thread Starter [Luke](https://wordpress.org/support/users/lukejongibson/)
 * (@lukejongibson)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/loop-first-header-tag/#post-6022129)
 * Excellent thank you. I will try these and let you know the results.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Loop – first header tag’ is closed to new replies.

## Tags

 * [header](https://wordpress.org/support/topic-tag/header/)
 * [homepage](https://wordpress.org/support/topic-tag/homepage/)
 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 3 participants
 * Last reply from: [Luke](https://wordpress.org/support/users/lukejongibson/)
 * Last activity: [11 years, 1 month ago](https://wordpress.org/support/topic/loop-first-header-tag/#post-6022129)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
