中继器高级自定义字段中的随机中继器
Random Repeater in a Repeater Advanced Custom Fields
我正在使用高级自定义字段并且在转发器中有一个转发器。我需要嵌套的中继器随机拉一排。这是我没有用的东西:
<?php $i = 0; while(the_repeater_field('squares')): ++$i;
$repeater = get_sub_field( 'images' );
$rand = rand(0, (count($repeater) - 1));?>
<a href="<?php the_sub_field('link'); ?>" class="fs-square" style="background-image:url('<?php echo $rand['four-square']; ?>')">
<div class="main-text"><?php the_sub_field('main_text'); ?></div>
<div class="icon-section">
<div class="icon"><?php the_sub_field('icon'); ?></div>
<div class="icon-text"><?php the_sub_field('icon_text'); ?></div>
</div>
</a>
<?php endwhile; ?>
基本上,我有一个正方形中继器,然后我有一个图像中继器。我需要图像中继器是随机的。
你可能想试试
<?php echo $repeater[$rand]['four-square']; ?>
而不是
<?php echo $rand['four-square']; ?>
HTH!
这是为我修复的。
<?php
$i = 0;
while(have_rows('squares')):
the_row();
$i++;
$repeater = get_sub_field( 'images' );
$rand = rand(0, (count($repeater) - 1)); //does not select a specific row but rather just a number
?>
<a href="<?php the_sub_field('link'); ?>" class="fs-square" style="background-image:url('<?php echo $repeater[$rand]['image']['sizes']['four-square']; ?>')">
<div class="main-text"><?php the_sub_field('main_text'); ?></div>
<div class="icon-section">
<div class="icon"><?php the_sub_field('icon'); ?></div>
<div class="icon-text"><?php the_sub_field('icon_text'); ?></div>
</div>
</a>
<?php endwhile; ?>
我正在使用高级自定义字段并且在转发器中有一个转发器。我需要嵌套的中继器随机拉一排。这是我没有用的东西:
<?php $i = 0; while(the_repeater_field('squares')): ++$i;
$repeater = get_sub_field( 'images' );
$rand = rand(0, (count($repeater) - 1));?>
<a href="<?php the_sub_field('link'); ?>" class="fs-square" style="background-image:url('<?php echo $rand['four-square']; ?>')">
<div class="main-text"><?php the_sub_field('main_text'); ?></div>
<div class="icon-section">
<div class="icon"><?php the_sub_field('icon'); ?></div>
<div class="icon-text"><?php the_sub_field('icon_text'); ?></div>
</div>
</a>
<?php endwhile; ?>
基本上,我有一个正方形中继器,然后我有一个图像中继器。我需要图像中继器是随机的。
你可能想试试
<?php echo $repeater[$rand]['four-square']; ?>
而不是
<?php echo $rand['four-square']; ?>
HTH!
这是为我修复的。
<?php
$i = 0;
while(have_rows('squares')):
the_row();
$i++;
$repeater = get_sub_field( 'images' );
$rand = rand(0, (count($repeater) - 1)); //does not select a specific row but rather just a number
?>
<a href="<?php the_sub_field('link'); ?>" class="fs-square" style="background-image:url('<?php echo $repeater[$rand]['image']['sizes']['four-square']; ?>')">
<div class="main-text"><?php the_sub_field('main_text'); ?></div>
<div class="icon-section">
<div class="icon"><?php the_sub_field('icon'); ?></div>
<div class="icon-text"><?php the_sub_field('icon_text'); ?></div>
</div>
</a>
<?php endwhile; ?>