php - 当转发器字段包含超过 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">•</strong> <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
解决方案
尝试这个:
<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">•</strong> <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>
推荐阅读
- oauth - 在 Datapower/API Connect [OAuth2] 中禁用一次刷新令牌?
- javascript - Angular2:如何在以编程方式从子组件更改输入属性但在父绑定中未更改后重置输入属性?
- java - 参数“registrationId”的类型应为“integer”,而不是“java.lang.Long”
- php - 如何在长空格之间获取数字(PHP Regex)
- java - MongoDB,WriteConcern:需要澄清一下
- javascript - 连续旋转 div,但仅使用 -180 度到 180 度和 css 转换(指南针)
- qt - 如何使 GridView 显示具有不同 cellWidth 和 cellHeight 的项目
- wordpress - WordPress 在自定义表数据中搜索
- symfony - 如何扩展无法修改的实体的功能?
- java - ImageView 或 CardView 的影子,如 Google Play 游戏