WordPress Advanced Custom Fields Repeater, wrap every 3 divs in a row

落爺英雄遲暮 提交于 2019-12-06 09:29:39

You can use this as a starting point. I haven't tested it so there might be slight problems in my logic, but this will get you most of the way there (if not all the way!).

if ( get_field( 'triple_column_2' ) ): ?>

    <?php $index = 1; ?>
    <?php $totalNum = count( get_field('triple_column_2') ); ?>

    <row>
    <?php while ( has_sub_field( 'triple_column_2' ) ): ?>


        <div class="col-sm-4">
            <?php the_sub_field( 'copy' ); ?>
        </div>
        <? if ($index % 3 == 0) : ?>
            <? if ($index < $totalNum) : ?>
                // more rows, so close this one and start a new one
                </row>
                <row>
            <? elseif ($index == $totalNum) : ?>
                // last element so close row but don't start a new one
                </row>
            <? endif; ?>

        <? endif; ?>

    <?php $index++; ?>
    <?php endwhile; ?>

<?php endif; ?>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!