Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // initiate the default wordpress loop as usual
- <?php if (have_posts()) : while(have_posts()) :
- // set a count variable to increase with each loop
- $i++;
- // test the variable modulus against a zero value
- // odd values return true, even values return false
- // see proceding discussion for more information
- if(($i % 2) == 0) :
- // skip to next post if variable is an even number
- $wp_query->next_post();
- // display the post if variable is an odd number
- else : the_post(); ?>
- // open a division for the left column
- <div id="left-column">
- // display the title of the post
- <h1><?php the_permalink(); ?></h1>
- // display the post content
- <?php the_content(); ?>
- // close the division
- </div>
- // close the first if statement
- <?php endif;
- // close the loop
- endwhile;
- // if there are no posts that meet the criteria
- else: ?>
- // display some alternate content
- <div>Alternate content</div>
- // close the second if statement
- <?php endif; ?>
- // reset the count variable to zero
- <?php $i = 0;
- // reset the loop
- rewind_posts(); ?>
- // the second loop is essentially the same as the first
- // the only difference is that we are testing the count variable against a non-zero value to display only even numbers
- <?php if (have_posts()) : while(have_posts()) : $i++; if(($i % 2) !== 0) : $wp_query->next_post(); else : the_post(); ?>
- // and of course a unique div id for the right column
- <div id="right-column">
- <h1><?php the_permalink(); ?></h1>
- <?php the_content(); ?>
- </div>
- <?php endif; endwhile; else: ?>
- <div>Alternate content</div>
- <?php endif; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement