Title: multiple loops on single.php?
Last modified: August 19, 2016

---

# multiple loops on single.php?

 *  [nickbudden](https://wordpress.org/support/users/nickbudden/)
 * (@nickbudden)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/multiple-loops-on-singlephp/)
 * Hi,
 * I’m trying to create multiple loops on single.php so that the single post is 
   shown on the top of the page, and the excerpt from the next post is shown below
   this. I’ve had no luck so far. I’ve tried query_posts with an offset of 1 (just
   gives me the 2nd most recent post) and I’ve tried coding a second loop without
   resetting the first, but just gives me the same post again.
 * Would anyone know a workaround?
 * Thanks,
 * Nick

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

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/multiple-loops-on-singlephp/#post-1576983)
 * You will need 2 Loops. In the first Loop (showing the appropriate single post),
   grab the id of the post as a variable. In the second Loop, try setting up a custom
   query using the post id variable +1.
 *  Thread Starter [nickbudden](https://wordpress.org/support/users/nickbudden/)
 * (@nickbudden)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/multiple-loops-on-singlephp/#post-1577042)
 * Hi,
 * Sorry, but variables are still a little bit beyond my skills. I’ve tried quite
   a few things with variables over the last hour but haven’t had any luck. Here
   is my latest attempt, which I haven’t been able to get working.
 * **Beginning of first loop:**
 *     ```
       <?php if ( have_posts() ) : ?>
       	 <?php while ( have_posts() ) : the_post(); ?>
                   <?php $addone = <?php the_ID(); ?>;
       		  $nextpost = $addone+1;
                   ?>
       ```
   
 * **End of first loop and beginning of second loop:**
 *     ```
       <?php endwhile; ?>
       	<?php endif; wp_reset_query(); ?>
   
       <?php $my_query = new WP_Query('showposts=1&p=$nextpost;'); ?>
          <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
       ```
   
 * Is this along the lines of what you had meant?
 * Thanks again,
 * Nick
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/multiple-loops-on-singlephp/#post-1577065)
 * It looks about right – although you might want to try:
 * `<?php $my_query = new WP_Query('posts_per_page=1&p=' . $nextpost); ?>`
 * Also, this is pure theory. I’ve never tried it myself.
 *  Thread Starter [nickbudden](https://wordpress.org/support/users/nickbudden/)
 * (@nickbudden)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/multiple-loops-on-singlephp/#post-1577069)
 * Didn’t work, but thanks for the effort.
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/multiple-loops-on-singlephp/#post-1577134)
 * [http://codex.wordpress.org/Function_Reference/get_adjacent_post](http://codex.wordpress.org/Function_Reference/get_adjacent_post)
 * to check it, make a print out of the whole object:
 * `<?php print_r( get_adjacent_post(false,'',true); ?>`
 * i think, the id of the prev post is:
    `<?php $prev_id = get_adjacent_post(false,'',
   true)->ID; ?>`

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

The topic ‘multiple loops on single.php?’ is closed to new replies.

 * 5 replies
 * 3 participants
 * Last reply from: [Michael](https://wordpress.org/support/users/alchymyth/)
 * Last activity: [15 years, 10 months ago](https://wordpress.org/support/topic/multiple-loops-on-singlephp/#post-1577134)
 * Status: not a support question

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
