I'm trying to create a custom post type loop in Wordpress. So far so good. I managed to do that. However, I would like an alternating layout for each item, like this:
Item1 > IMAGE / DESCRIPTION
Item2 > DESCRIPTION / IMAGE
Item3 > IMAGE / DESCRIPTION
Item4 > DESCRIPTION / IMAGE
You get the idea. I'm fairly new to PHP, how would you change this loop?
<?php
$loop = new WP_Query( array( 'post_type' => 'menus', 'category_name' => '', 'ignore_sticky_posts' => 1, 'paged' => $paged ) );
while ( $loop->have_posts() ): the_post() ?>
<?php if ( $wp_query->current_post % 2 == 0 ) : ?>
<h2><?php echo get_the_title(); ?></h2>
<h2><?php echo the_content(); ?></h2>
<?php else: ?>
<h2><?php echo the_content(); ?></h2>
<h2><?php echo get_the_title(); ?></h2>
<?php endif ?>
<?php endwhile ?>
?>
Thing is, if I do it like this I run into an undefined offset error. So I'm wondering what would be the right way to achieve this. Any input is appreciated!