Title: Incrementing the Loop manually
Last modified: August 19, 2016

---

# Incrementing the Loop manually

 *  Resolved [RyanJenkins](https://wordpress.org/support/users/ryanjenkins/)
 * (@ryanjenkins)
 * [17 years ago](https://wordpress.org/support/topic/incrementing-the-loop-manually/)
 * I’ve got a mini-loop on my homepage.
 * It looks like this:
 *     ```
       <?php
       // Include WordPress
       define('WP_USE_THEMES', false);
       require('./blog/wp-blog-header.php');
       query_posts('showposts=2');
       ?>
   
       [Plenty of homepage content]
   
       <?php while(have_posts()): the_post(); ?>
       <br /><span class="blogtitle"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span>
       <span class="blogdate"><?php the_time('F jS, Y') ?></span>
       <?php the_excerpt(); ?>
       <hr noshade style="margin-top:14px;margin-bottom:-4px;padding:0px;">
       <?php endwhile; ?>
       ```
   
 * The Loop goes through two posts and after each one places a horizontal rule, 
   just like it’s told to. This ends up looking silly, though, because after my 
   second post, there is a horizontal rule, and then the very bottom of the website,
   nothing after it. I’d like to do away with this.
 * So, what I could do is something like this:
 *     ```
       <?php while(have_posts()): the_post(); ?>
       <br /><span class="blogtitle"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span>
       <span class="blogdate"><?php the_time('F jS, Y') ?></span>
       <?php the_excerpt(); ?>
       <hr noshade style="margin-top:14px;margin-bottom:-4px;padding:0px;">
   
       [manually increment the Loop to the next post, then paste the same code to display and format the post]
   
       <br /><span class="blogtitle"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span>
       <span class="blogdate"><?php the_time('F jS, Y') ?></span>
       <?php the_excerpt(); ?>
       <?php endwhile; ?>
       ```
   
 * Is there a function for this, to skip, continue, increment, or iterate the Loop?
   Thanks.

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

 *  [stvwlf](https://wordpress.org/support/users/stvwlf/)
 * (@stvwlf)
 * [17 years ago](https://wordpress.org/support/topic/incrementing-the-loop-manually/#post-1079133)
 * Here is code for how to do what you want
 * In this example, output an <hr> after all posts except the last one
 *     ```
       <?php
       if( ($wp_query->current_post + 1) < ($wp_query->post_count) ) {
         echo("<hr />");
       }  ?>
       ```
   
 * (post_count starts at 1 and current_post starts at 0. )
 *  Thread Starter [RyanJenkins](https://wordpress.org/support/users/ryanjenkins/)
 * (@ryanjenkins)
 * [17 years ago](https://wordpress.org/support/topic/incrementing-the-loop-manually/#post-1079295)
 * Fantastic, perfect, thanks a million.

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

The topic ‘Incrementing the Loop manually’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [RyanJenkins](https://wordpress.org/support/users/ryanjenkins/)
 * Last activity: [17 years ago](https://wordpress.org/support/topic/incrementing-the-loop-manually/#post-1079295)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
