Skip to content

Instantly share code, notes, and snippets.

@jaclyntan
Created February 1, 2017 03:11
Show Gist options
  • Save jaclyntan/e29c22c3a2f582e392c159505287ce2e to your computer and use it in GitHub Desktop.
Save jaclyntan/e29c22c3a2f582e392c159505287ce2e to your computer and use it in GitHub Desktop.
Automatic bootstrap rows in the WordPress loop
<?php
$counter = 0;
while ( have_posts() ) : the_post();
$counter++;
if ($counter === 1) {
echo '<div class="row">';//start the row
}
echo '<div class="col-sm-__NAME__">';//start the col//
get_template_part( 'template-parts/content', 'page' );
echo '</div>';//end the col
if ($counter === 3) {
$counter = 0; //reset counter
echo '</div>'; //end row
}
endwhile; // End of the loop.
if ($counter !== 0) {
echo '</div>'; //closes stray rows
}
?>
@ErikRobles
Copy link

Thank you for this code. It worked wonders.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment