【发布时间】:2018-05-09 05:02:31
【问题描述】:
我不确定我这样做是否正确?我有一个嵌套的 ACF 中继器,它工作正常,但该部分都显示为一个单独的块。我希望能够将块分成列。所以我想这样做我需要一个“foreach”语句,这样我就可以为每个部分分配一个 id 或类,让我能够单独设置每个部分的样式 - 浮动和添加边距等。
我不能让它工作!
<div class="col-xl-12 food-section">
<?php
$rows = get_field('section_container');
if($rows) {
foreach($rows as $row):
?>
<div class="col-xl-6 section-test"> <?php
if( have_rows('section_container') ) :
while( have_rows('section_container') ): the_row(); ?>
<h1><?php the_sub_field('section_heading'); ?></h1>
<div class="section-image"><?php
$image = get_sub_field('section_image');
if( !empty($image) ): ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
</div>
<?php endif;
if( have_rows('sub_section_container') ):
while( have_rows('sub_section_container') ): the_row();
?>
<h2><?php the_sub_field('sub_section_heading'); ?></h2>
<?php
if( have_rows('food_item') ):
while( have_rows('food_item') ): the_row();
?>
<div id="menu-table">
<h3 id="leftside"><?php the_sub_field('item_name'); ?></h3>
<h4 id="rightside"><?php the_sub_field('price'); ?></h4>
<div id="menu-description"><p><?php the_sub_field('item_description'); ?></p></div>
<div class="stroke"></div>
</div>
<?php endwhile; //food_item
endif; //food_item
endwhile; //section_h1_container
endif; //section_h1_container
endwhile; //section_container
endif; //section_container
wp_reset_postdata();
endforeach; }
?></div>
</div><!-- food-section -->
【问题讨论】:
-
添加php标签可能会获得更多浏览量
-
“while(have_rows('section_container')): the_row();”与您的 foreach 执行相同的工作,并且“if( have_rows('section_container') ) :”与您的 foreach 上方的 if 语句执行相同的工作。看看这里阅读嵌套中继器:advancedcustomfields.com/resources/…
标签: php arrays foreach repeater advanced-custom-fields