Skip to content

Instantly share code, notes, and snippets.

@tjhole
Created January 15, 2014 15:17
Show Gist options
  • Save tjhole/8438083 to your computer and use it in GitHub Desktop.
Save tjhole/8438083 to your computer and use it in GitHub Desktop.
WORDPRESS: Query Posts - Break into Rows
<?php
$args = array(
'post_type' => 'posts',
'posts_per_page' => -1,
);
$total = 0;
query_posts($args);
while ( have_posts() ) : the_post();
$total++; endwhile; wp_reset_query();
query_posts($args);
$countimg = 0; while ( have_posts() ) : the_post(); $countimg++;
if($countimg == 1) { echo "<div class='row'>";} ?>
<div class="columns large-3">
<?php echo $countimg; echo ": "; the_title();?>
</div>
<?php
if ( $countimg == ($total) ) {
echo "</div>";
} else {
if ( $countimg % 4 == 0 ) { echo "</div><div class='row'>";}
}
endwhile; wp_reset_query(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment