2015-09-30 79 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!

相關問題