Title: multiple loop question
Last modified: August 20, 2016

---

# multiple loop question

 *  Resolved [hyperdrive](https://wordpress.org/support/users/hyperdrive/)
 * (@hyperdrive)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/multiple-loop-question-4/)
 * Hello,
 * I have a loop in the header for slide images which is affecting the loop in single.
   php. What is the correct way to format so it doesn’t affect the main loops?
 * This is the header loop im using.
 *     ```
       <?php query_posts('showposts=4'); ?>
         <?php while (have_posts()) : the_post(); ?>
       		<?php
       		if ( has_post_thumbnail() ) {
       		  the_post_thumbnail('large-image');
       		}
       		?>
       <?php endwhile; ?>
       ```
   

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/multiple-loop-question-4/#post-3422703)
 * see some discussion about this in [http://wordpress.stackexchange.com/questions/1753/when-should-you-use-wp-query-vs-query-posts-vs-get-posts?rq=1](http://wordpress.stackexchange.com/questions/1753/when-should-you-use-wp-query-vs-query-posts-vs-get-posts?rq=1)
 * definitively do not use `query_posts()` – possibly use `WP_Query()`;
    and always
   reset the postdata after the loop.
 * example:
 *     ```
       <?php $header_slides = new WP_Query( array( 'posts_per_page' => 4 ) ); ?>
         <?php while ($header_slides->have_posts()) : $header_slides->the_post(); ?>
       		<?php
       		if ( has_post_thumbnail() ) {
       		  the_post_thumbnail('large-image');
       		}
       		?>
       <?php endwhile; wp_reset_postdata(); ?>
       ```
   
 * [http://codex.wordpress.org/Class_Reference/WP_Query](http://codex.wordpress.org/Class_Reference/WP_Query)
 *  Thread Starter [hyperdrive](https://wordpress.org/support/users/hyperdrive/)
 * (@hyperdrive)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/multiple-loop-question-4/#post-3422708)
 * Thank you much!

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

The topic ‘multiple loop question’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [hyperdrive](https://wordpress.org/support/users/hyperdrive/)
 * Last activity: [13 years, 3 months ago](https://wordpress.org/support/topic/multiple-loop-question-4/#post-3422708)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
