I'm trying to make a little bit of a bootstrap layout for a Wordpress theme using Advanced Custom Fields. I have it set up at the moment, so if you have 2 fields of content, it generates a "6" width column. If you have 3 fields it generates a "4" field column instead.
<?php if(get_field('link_tiles')) :
while (has_sub_field('link_tiles')) :
$number_of_cols = count(get_field( 'link_tiles' ));
if ($number_of_cols == 2) {
echo '<div class="col-md-6" style="padding: 0; margin: 0;">';
}
elseif ($number_of_cols >= 3) {
echo '<div class="col-md-4" style="padding: 0; margin: 0;">';
}
?>
What I really want now though, is make it so if you have 4 fields entered, it generates 3x "4" width columns and then 1x "6" width column and then if you have 6 fields entered it goes back to generating "4" width columns. I imagine it would take some logic using a While Loop, but I can't quite figure out the logic of it. I'm quite new to PHP, any help will be appreciated!