当在前端显示我的中继器字段时,它将显示该列表中除第一个项目之外的所有内容。我希望它能显示中继器中的所有内容。
<?php if( have_rows('the_list') ): the_row(); ?>
<div class="row">
<?php while( have_rows('the_list') ): the_row(); ?>
<div class="col-md-8">
<h6><?php the_sub_field('name') ?></h6>
<p><?php the_sub_field('number') ?></p>
</div>
<?php endwhile; ?>
</div>
<?php endif; ?>
发布于 2016-04-07 00:24:16
您正在运行the_row();
两次。从if语句后面删除它可以解决您的问题。
以下是更新后的代码片段:
<?php if( have_rows('the_list') ): ?>
<div class="row">
<?php while( have_rows('the_list') ): the_row(); ?>
<div class="col-md-8">
<h6><?php the_sub_field('name') ?></h6>
<p><?php the_sub_field('number') ?></p>
</div>
<?php endwhile; ?>
</div>
<?php endif; ?>
发布于 2021-04-27 14:00:59
<?php global $post; ?>
<?php if( have_rows('the_list'), $post->ID ): ?>
<div class="row">
<?php while( have_rows('the_list'), $post->ID ): the_row(); ?>
<div class="col-md-8">
<h6><?php the_sub_field('name') ?></h6>
<p><?php the_sub_field('number') ?></p>
</div>
<?php endwhile; ?>
</div>
<?php endif; ?>
https://stackoverflow.com/questions/36453619
复制相似问题