Title: Run loop twice?
Last modified: August 18, 2016

---

# Run loop twice?

 *  [yansky](https://wordpress.org/support/users/yansky/)
 * (@yansky)
 * [19 years, 1 month ago](https://wordpress.org/support/topic/run-loop-twice/)
 * Hi, I’d like to have my index page show post titles (but no content) from one
   category in one div and posts titles from another category in an adjacent div.
 * My current approach to this is to run the loop twice (once inside of each div),
   but I was wondering if there was a more efficient way to do it.
 * I have tried starting the loop before both divs, but then it generates multiple
   copies of each div for each post title it finds.
 * Here is my current code for the two divs:
 *     ```
       <div id="content-left">
       		<ul>
       		<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
       			<li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>
       			<small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small></li>
       			<?php endwhile; ?>
       		</ul>
       		<?php else : ?>
       			<h2 class="center">Not Found</h2>
       			<p class="center"><?php _e("Sorry, no posts matched your criteria."); ?>
   
       		<?php endif; ?>
       </div>			 
   
       <div id="content-right">
       		<ul>
       		<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
       			<li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>
       			<small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small></li>
       		<?php endwhile; ?>
       		</ul>
       		<?php else : ?>
       			<h2 class="center">Not Found</h2>
       			<p class="center"><?php _e("Sorry, no posts matched your criteria."); ?>
   
       		<?php endif; ?>
       </div>
       ```
   

The topic ‘Run loop twice?’ is closed to new replies.

## Tags

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

 * 0 replies
 * 1 participant
 * Last reply from: [yansky](https://wordpress.org/support/users/yansky/)
 * Last activity: [19 years, 1 month ago](https://wordpress.org/support/topic/run-loop-twice/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
