I want to count the custom fields and give the columns the right width to work with Bootstrap 3.
If there are 2 entries I want it to be:
<div class="col-md-6">
If there are 3 entries I want it to be:
<div class="col-md-4">
But it just puts the count number in each div
.
EDIT: The solution of "num8er" helped me a lot, THX again! If someone finds this - this is how it works with a normal wordpress loop:
<?php
if ( have_posts() ): ?>
<?php $elements = [];
while ( have_posts() ): the_post();
$element = get_the_title();
$elements[] = $element;
endwhile;
if(sizeof($elements)>0) {
$size = ceil(12 / sizeof($elements));
if($columns<2) $columns = 2;
foreach($elements AS $element) {
echo '<div class="col-md-'.$size.'">'.$element.'</div>';
}
}
endif;
?>
E. g. this is the DOM if i have 6 articles:
<div class="col-md-2"><h2>Homer Simpson’s Guide to Tom Cruise</h2></div>
<div class="col-md-2"><h2>Homer Simpson’s Guide to Tom Cruise</h2></div>
...