Skip to content

Instantly share code, notes, and snippets.

@laurenclark
Last active August 29, 2015 14:05
Show Gist options
  • Save laurenclark/2469203d016787df78d7 to your computer and use it in GitHub Desktop.
Save laurenclark/2469203d016787df78d7 to your computer and use it in GitHub Desktop.
Custom Fields - Alternating Layout Boxes
//Requires Advanced Custom Fields PLugin and Custom Post Types UI
//Use <?php the_field('field_name') ?> to insert the fields into block.
<?php
$args = array(
'post_type' => 'your_custom_post_type',
'orderby' => 'date',
'order' => 'ASC',
);
$reference = new WP_Query( $args );
?>
<?php /* Start loop */ ?>
<?php if ( have_posts() ) { ?>
<?php while ( $reference->have_posts() ) { ?>
<?php $staff->the_post(); ?>
<?php if (0 === $reference->current_post %2 ) { ?>
<!-- do stuff for odd post -->
<!-- ODD -->
<section class="odd-box">
<div class="row">
</div>
</section>
<?php continue; ?>
<?php } ?>
<!-- do stuff for even posts -->
<!-- Even -->
<section class="odd-box">
<div class="row">
</div>
</section>
<?php } ?>
<?php } ?>
<?php /* End Loop */ ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment