0

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>
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
    Sep 24, 2019 at 20:11
  • hope i made clear about relationship with WordPress
    – syner
    Sep 24, 2019 at 20:51

1 Answer 1

0

solution 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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.