最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览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>

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>
发布评论

评论列表(0)

  1. 暂无评论