Skip to content

Instantly share code, notes, and snippets.

@wwdboer
Last active December 10, 2015 00:48
Show Gist options
  • Save wwdboer/4353601 to your computer and use it in GitHub Desktop.
Save wwdboer/4353601 to your computer and use it in GitHub Desktop.
WordPress: Modulo example to create rows
<?php
global $post;
$args = array(
'post_type' => 'post',
'posts_per_page' => -1
);
$new_query = new WP_Query($args);
$post_count = 0;
$total_posts = $new_query->post_count;
?>
<?php while( $new_query->have_posts() ) : $new_query->the_post(); ?>
<?php $post_count++ ?>
<?php if ($post_count % 3 == 1) : ?>
<div class="row-fluid">
<?php endif; ?>
<div class="span4">
</div>
<?php if ( $post_count % 3 == 0 || $post_count == $total_posts ) : ?>
</div>
<?php endif; ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment