Im using Acf Custom field in wordpress to get my custom field in Acf Reapter as below:
<?php if(have_rows('field_name')):?>
<?php
$i = 1;
while(have_rows('field_name')):the_row();
$total= count(get_field ('field_name'));
?>
<div class="<?php echo ($i % 2 == 0 )?'col-md-6':'col-md-12'; ?>" id="<?php echo $i; ?>">
<h1><?php the_sub_field('services_title'); ?></h1>
</div>
<?php $i++; endwhile; ?>
<?php endif;?>
so,i need following condition to be applied in this acf while loop:
i have bootstrap column in while loop, what i want is if bootstrap last column is odd then i want column to be 12 (col-12), i found the way to check number even or odd but want to check last number so if last number (last column) is odd i want column to be 12 else remain col-6 i have tried:
<div class"<?php echo ($i == (2 || 4 || 6) )?'col-md-6':'col-md-12'; ?>">
display content there in while loop
</div>
<div class" <?php echo ($i % 2 == 0)?'col-md-6':'col-md-12'; ?>">
display content there in while loop
</div>
Im using Acf Custom field in wordpress to get my custom field in Acf Reapter as below:
<?php if(have_rows('field_name')):?>
<?php
$i = 1;
while(have_rows('field_name')):the_row();
$total= count(get_field ('field_name'));
?>
<div class="<?php echo ($i % 2 == 0 )?'col-md-6':'col-md-12'; ?>" id="<?php echo $i; ?>">
<h1><?php the_sub_field('services_title'); ?></h1>
</div>
<?php $i++; endwhile; ?>
<?php endif;?>
so,i need following condition to be applied in this acf while loop:
i have bootstrap column in while loop, what i want is if bootstrap last column is odd then i want column to be 12 (col-12), i found the way to check number even or odd but want to check last number so if last number (last column) is odd i want column to be 12 else remain col-6 i have tried:
<div class"<?php echo ($i == (2 || 4 || 6) )?'col-md-6':'col-md-12'; ?>">
display content there in while loop
</div>
<div class" <?php echo ($i % 2 == 0)?'col-md-6':'col-md-12'; ?>">
display content there in while loop
</div>
Share
Improve this question
edited Sep 24, 2019 at 20:50
syner
asked Sep 24, 2019 at 20:03
synersyner
12 bronze badges
2
- A while WordPress loop? How does this relate to WordPress? Could you please edit your question and display the while loop you're working with? – Howdy_McGee ♦ Commented Sep 24, 2019 at 20:11
- hope i made clear about relationship with WordPress – syner Commented Sep 24, 2019 at 20:51
1 Answer
Reset to default 0solution By m_hutley
<div class="<?php echo ($i == $total && $total % 2 !== 0 )?'col-md-12':'col-md-6'; ?>" id="<?php echo $i; ?>">
<h1><?php echo "contain"; ?></h1>
</div>