Created
February 1, 2017 03:11
-
-
Save jaclyntan/e29c22c3a2f582e392c159505287ce2e to your computer and use it in GitHub Desktop.
Automatic bootstrap rows in the WordPress loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this code. It worked wonders.