首页 > 解决方案 > ACF 中继器 - 应用不同的行最后一个中继器

问题描述

我在我的 wordpress 网站中使用 ACF 中继器。

每个中继器显示在col-md-6. 我想显示最后一个col-md-12.

<div class="container">
            <?php if ( have_rows( 'salon' ) ) : ?>
            <div class="row">
                <?php while ( have_rows( 'salon' ) ) : the_row(); ?>
                <div class="col-md-6">
                    <div class="card">
                        <div class="card-body">
                            <h2 class="card-title">Card title</h2>
                            <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
                        </div>
                    </div>
                </div>
                <?php endwhile; ?>
            </div>
            <?php endif; ?>
        </div>

标签: wordpressbootstrap-4advanced-custom-fields

解决方案


用你的代码试试这个例子,它对我有用。

<?php if( have_rows('services_repeater', $services) ): ?>
    <?php $rowCount = count( get_field('services_repeater', $services) ); //GET THE COUNT ?>
    <?php $i = 1; ?>
    <?php while( have_rows('services_repeater', $services) ): the_row(); ?>

        <?php // vars
            $service = get_sub_field('service');
            $description = get_sub_field('description');
        ?>

        <span class="hint--bottom" data-hint="<?php echo $description; ?>"><?php echo $service; ?></span>
        <?php if($i < $rowCount): ?>
            <div id="separator"> / </div>
        <?php endif; ?>
        <?php $i++; ?>
    <?php endwhile; ?>
<?php endif; ?>

推荐阅读