I have two columns and I want one post type to get distributed to each column evenly. So itâs two side-by-side divs and I want:
Div1 = Post1, Post3, Post5
Div2 = Post2, Post4, Post6
So basically get odd/even posts. Not exactly sure how to do it.
<?php query_posts('post_type=post-type'); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="column1">
<?php
//Get Odd Posts
?>
</div>
<div class="column2">
<?php
//Get Even Posts
?>
</div>
<?php endwhile; ?>
<?php else : ?>
//Something that happens when a post isnât found.
<?php endif; ?>
You want to use the modulus operator something like this:
To do what you want, first you have to store the results somewhere (as even/odd), then display them.
Though you should really target these posts with CSS, not PHP, as it’s hackish at best.