• 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.