简体   繁体   English

每3个foreach添加一个清除div

[英]Add A clear div every 3rd foreach

I want to add a clear div (that is, <div class="clear></div> ) after every 3rd term, but I am having difficulties doing this within a foreach block. I can, however, within a while loop. 我想在每个第3个学期后添加一个清晰的div (即<div class="clear></div> ),但是我很难在foreach块中执行此操作,但是可以在while循环中进行。

Any help is greatly appreciated. 任何帮助是极大的赞赏。

<?php 

$terms = get_field('feature_choices');
// print_r($terms);
if( $terms ): ?>

<?php foreach( $terms as $term ): ?>

    <div class="col-sm-3 margin_bottom">
        <div class="row">
            <div class="col-xs-2">
                <img src="<?php bloginfo('template_directory'); ?>/assets/img/checkmark.png" alt="" />
            </div>
            <div class="col-xs-10">
                <?php echo $term->name; ?>
            </div>
        </div>
    </div>

<?php endforeach; ?>
<?php endif; ?>

add a counter 添加一个柜台

<?php $count = 1; foreach( $terms as $term ): ?>

    <div class="col-sm-3 margin_bottom">
        <div class="row">
            <div class="col-xs-2">
                <img src="<?php bloginfo('template_directory'); ?>/assets/img/checkmark.png" alt="" />
            </div>
            <div class="col-xs-10">
                <?php echo $term->name; ?>
            </div>
        </div>
    </div>
<?php if( $count % 3 == 0 ) echo "\n".'<div class="clear"></div>'; ?>
<?php $count++; endforeach; ?>
<?php endif; ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM