• Hey guys!

    I’m displaying blog posts in two columns. I have two loops working really great with the rewind_posts(); function.

    The problem I’m having now is that I need to sort those loops with a couple of variables: number of posts and category name.

    I’m not sure how to integrate those two variables into the loops I’m using. Here is my loop right now which is displaying the most recent posts into right and left columns:

    <?php if (have_posts()) : while(have_posts()) : $i++; if(($i % 2) == 0) : $wp_query->next_post(); else : the_post(); ?>
    
    <div id="left-column">
    <h3><?php the_title(); ?></h3>
    <?php the_excerpt(); ?>
    </div> <!-- end #left-column -->
    
    <?php endif; endwhile; else: ?>
    <div>Alternate content</div>
    <?php endif; ?>
    </div> <!-- end .column-werap-left -->
    
    <?php $i = 0; rewind_posts(); ?>
    
    <?php if (have_posts()) : while(have_posts()) : $i++; if(($i % 2) !== 0) : $wp_query->next_post(); else : the_post(); ?>
    
    <div id="right-column">
    <h3><?php the_title(); ?></h3>
    <?php the_excerpt(); ?>
    </div> <!-- end #right-column -->
    
    <?php endif; endwhile; else: ?>
    <div>Alternate con
  • The topic ‘Adding variables to loop’ is closed to new replies.