php - Check If bootstrap last column is even or odd (using ACF custom field)

Im using Acf Custom field in wordpress to get my custom field in Acf Reapter as below:<?php if(have_rows('field_

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
Add a comment  | 

1 Answer 1

Reset to default 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>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745132358a4613033.html

相关推荐

  • php - Check If bootstrap last column is even or odd (using ACF custom field)

    Im using Acf Custom field in wordpress to get my custom field in Acf Reapter as below:<?php if(have_rows('field_

    8小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信