2015-09-30 41 views
0

我正在使用高级定制字段并在中继器中有中继器。我需要嵌套的中继器随机抽取一行。这里是我有什么不工作:中继器中的随机中继器高级定制字段

<?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; ?> 

基本上,我有一个正方形的中继器,然后在我对图像的中继器。我需要图像中继器是随机的。

回答

0

这是什么修复了我。

<?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; ?> 
0

你可能想尝试

<?php echo $repeater[$rand]['four-square']; ?> 

,而不是

<?php echo $rand['four-square']; ?> 

HTH!

相关问题