Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

Gabriel Ward
20,222 PointsCreating columns in a Wordpress Theme
I want to create a simple two column layout like the following on this page:
http://letterbox-mag.com/story.html
Here is the code in my index.php file:
<?php get_header(); ?>
<div class="grid-container">
<div class="grid-5">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<p><?php the_content(); ?></p>
<?php endwhile; else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
</div>
<div class="grid-5">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<p><?php the_content(); ?></p>
<?php endwhile; else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
</div>
</div>
<?php get_footer(); ?>
Each div class='grid-5' represents a column, so there are two columns. However at the moment each column shows all four of my posts. I want the posts to be displayed over both of the columns. So that column one displays the first two posts, and the second displays the last two posts. In short, how do I split the php code over the two columns?
Thanks in advance for any help.
1 Answer

Jacobus Hindson
14,429 PointsYou can use the current_post parameter in your code to separate posts into Odd/Even with a code block similar to this.
<?php while ($query->have_posts()): $query->the_post() ?>
<?php if ($query->current_post % 2 == 0): ?>
Gabriel Ward
20,222 PointsGabriel Ward
20,222 PointsWow thanks Jacobus, how would I use this within a multiple loop ?
This is what I've got but it's not working