首页 > 解决方案 > 当转发器字段包含超过 6 个值时,创建一个新的引导列

问题描述

我正在尝试使用 ACF 中继器字段和自定义帖子类型构建餐厅菜单自定义帖子类型的标题告诉类别,例如烧烤,repeater_fields 显示菜单项问题是我想创建一个新的引导列时li 在循环中达到 6 个项目。

<div class="fadeIn col-lg-12 col-sm-12 col-md-12" >
<?php $loop = new WP_Query(array('post_type'=>'menu'));
    if($loop->have_posts()) :
        $i=0;
        ?>
        <div class="row">
    <?php while($loop->have_posts() ): $loop->the_post(); ?> 
<ul style="width:50%" class="menu-list col-md-6 column  <?php echo the_title(); ?>">
        <?php while(the_repeater_field('item')):  ?>
        <li style="max-width:1000px;"><strong class="icon">&#x2022;</strong>&nbsp;<b><?php the_sub_field('heading'); ?></b><span class="price" >1.95</span><br><strong style="font-weight:400;margin-left:22px;">Soybean paste broth</strong></li>
        <?php  endwhile;?>  
    </ul>
 <?php endwhile;  endif; ?>
</div>

</div>

如果 li 中的项目超过 5 项,我想自动创建一个新的 col-md-6 ul

标签: phpwordpressadvanced-custom-fields

解决方案


尝试这个:

<div class="fadeIn col-lg-12 col-sm-12 col-md-12" >
    <?php $loop = new WP_Query(array('post_type'=>'menu'));
    if($loop->have_posts()) :
    $i=0;
    ?>
    <div class="row">
        <?php while($loop->have_posts() ): $loop->the_post(); ?>
            <?php $j = 0; ?>
        <ul style="width:50%" class="menu-list col-md-6 column  <?php echo the_title(); ?>">
            <?php while(the_repeater_field('item')):  ?>
                <?php if ($j === 5): ?>
                    </ul><ul style="width:50%" class="menu-list col-md-6 column  <?php echo the_title(); ?>">
                    <?php $j = 0; ?>
                <?php endif; ?>
                <li style="max-width:1000px;"><strong class="icon">&#x2022;</strong>&nbsp;<b><?php the_sub_field('heading'); ?></b><span class="price" >1.95</span><br><strong style="font-weight:400;margin-left:22px;">Soybean paste broth</strong></li>
                <?php $j++; ?>
            <?php  endwhile;?>
            </ul>
        <?php endwhile;  endif; ?>
    </div>
</div>

推荐阅读