I am trying to create a layout with two different divs alternating vertically. For example the even has to be: picture + content; and the odd has to be: content + picture.
Here is my code, at the moment it prints every post doubled, once per div:
<div id="content">
<?php if (have_posts()) : while(have_posts()) : $i++; if(($i % 2) == 0) : the_post(); ?>
<div id="leftcontent_1">
<a href="<?php the_permalink(); ?>"><img src="<?php echo $image ?>"/></a>
</div>
<div id="rightcontent_1">
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></a></h2>
<?php the_content(); ?>
</div>
<div class="clear"></div>
<?php else : ?>
<div id="rightcontent_2">
<a href="<?php the_permalink(); ?>"><img src="<?php echo $image ?>"/></a>
</div>
<div id="leftcontent_2">
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></a></h2>
<?php the_content(); ?>
</div>
<div class="clear"></div>
<?php endif; endwhile; endif; ?>
</div>
Any hint on how can I fix it?
Thank you in advance.
$i++; if(($i % 2) == 0) : $wp_query->next_post(); else : the_post();
In this way it is working a 50%.