Title: Alternate query_posts output
Last modified: August 19, 2016

---

# Alternate query_posts output

 *  [albertpr9](https://wordpress.org/support/users/albertpr9/)
 * (@albertpr9)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/alternate-query_posts-output-2/)
 * Hi,
 * How can I get the query_posts to alternate the output?
 * Ex; instead of this:
 *     ```
       <h1>Header 1</h2>
       <p>text</p>
       <!-- end of post -->
       <h1>Header 2</h2>
       <p>text</p>
       <!-- end of post -->
       <h1>Header 2</h2>
       <p>text</p>
       <!-- end of post -->
       ```
   
 * I’d like to get this:
 *     ```
       <h1>Header 1</h2>
       <p>text</p>
       <!-- end of post -->
       <h1 class="hd2">Header 2</h2>
       <p>text</p>
       <!-- end of post -->
       <h1>Header 2</h2>
       <p>text</p>
       <!-- end of post -->
       ```
   
 * You know what I mean??? So I can get the posts presented in an alternate way 
   from each other…
 * Thanks for the help in advance.

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/alternate-query_posts-output-2/#post-1380065)
 * one of the ways is to use a counter, check for odd/even, add the extra class 
   to odd headers, increment the counter after the post.
 *     ```
       <?php $counter=0;
       if (have_posts()) :
          while (have_posts()) :
       ?>
       <h1 <?php if($counter%2 != 0) { echo 'class="hd2"'; } ?>><?php the_title(); ?></h1>
        <?php     the_content();
       $counter++;
          endwhile;
       endif;
       ?>
       ```
   
 * for a different way see: [http://adambrown.info/b/widgets/easy-php-tutorial-for-wordpress-users/posts-that-have-alternating-colors/](http://adambrown.info/b/widgets/easy-php-tutorial-for-wordpress-users/posts-that-have-alternating-colors/)
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/alternate-query_posts-output-2/#post-1380114)
 * Continue discussion here:
    [http://wordpress.org/support/topic/362571](http://wordpress.org/support/topic/362571)
 * I also deleted another thread of the same subject.
 * [@albertpr9](https://wordpress.org/support/users/albertpr9/) – Please do not 
   post duplicate topics.

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

The topic ‘Alternate query_posts output’ is closed to new replies.

## Tags

 * [query_posts](https://wordpress.org/support/topic-tag/query_posts/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 3 participants
 * Last reply from: [MichaelH](https://wordpress.org/support/users/michaelh/)
 * Last activity: [16 years, 3 months ago](https://wordpress.org/support/topic/alternate-query_posts-output-2/#post-1380114)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
