【问题标题】:Random Repeater in a Repeater Advanced Custom Fields中继器高级自定义字段中的随机中继器
【发布时间】:2015-12-28 11:42:28
【问题描述】:

我正在使用高级自定义字段,并且在转发器中有转发器。我需要嵌套中继器随机拉一排。这是我所拥有的不起作用的:

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

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

【问题讨论】:

    标签: wordpress advanced-custom-fields


    【解决方案1】:

    你可以试试

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

    而不是

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

    HTH!

    【讨论】:

      【解决方案2】:

      这就是为我解决的问题。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-02-01
        • 2018-08-15
        • 2020-05-03
        • 2021-03-01
        • 2015-06-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多