PHP Loop to Output Rows and Columns Using Flexbox
Jul 31, 2020 | Flexbox, PHP
function xxx_function(){
$rows = 1;
$cols = 4; ?>
<div class="xxx-row"> <?php
if ( $query->have_posts() ){
while ( $query->have_posts() ){ $query->the_post(); ?>
<div class="xxx-col"> <?php
// Do shit here.
if($rows % $cols == 0){ ?>
</div> <div class="xxx-row"> <?php
}
$rows++;
} ?>
</div> <?php
$rows = 1;
}
}
PHP loop that outputs evenly spaced columns and rows using Flexbox. To change the number of columns, edit the $cols variable.