【问题标题】:Repeater inside Group and the both are inside Group ACF Wordpress组内的中继器,两者都在组 ACF Wordpress 内
【发布时间】:2020-06-08 22:12:42
【问题描述】:

我正在开发 Wordpress 中的 ACF 插件,我将这个 HTML 代码分成 3 个部分。 第一部分是该父组内的父组还有子组子组内有repeater。 我试图像这样解决它[4] 但它没有用。这些图片可以解释更多

image 1

image 2

image 3

<!--The Parent Group (section2_technology)-->
<div class="section2">
  <div class="container">
    <div class="right">
      <div class="frame">
        <!-- The (qoute) text -->
        We use modern, proven technologies and approaches that allow us to effectively extend and scale our products.
      </div>
    </div>
    <div class="left">
      <div class="top">
        <hr>
        <span>MOBILE</span>
        <hr>
      </div>
      <!-- The Child Group class='mobile' -->
      <div class="bottom" id="mobile">
        <div data-aos="flip-up">
          <div class="slide-down frame1">
            <div class="main-hover">
              <div class="mobile">
                IOS
              </div>
              <div class="split"></div>
              <div class="content-div">
                <div class="slide-down__top">
                  <!-- The Repeater class='type' -->
                  <div class="type">
                    <img src="" alt="" class="mobileicons-img">
                    <div class="name"></div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div data-aos="flip-down" data-aos-delay="200">
          <div class="slide-down">
            <div class="main-hover">
              <div class="mobile">
                ANDROID
              </div>
              <div class="split"></div>
              <div class="content-div">
                <div class="slide-down__top">
                  <!-- This is the repeater class='type' -->
                  <div class="type">
                    <img src="" alt="" class="mobileicons-img">
                    <div class="name">Java</div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

【问题讨论】:

    标签: php wordpress advanced-custom-fields acfpro


    【解决方案1】:

    您的 PHP 应该如下所示:

    <?php if ( have_rows('parent-group') ): ?>
        <!-- html before -->
        <?php while ( have_rows('parent-group') ) : the_row(); ?>
    
            <?php if ( have_rows('child-group') ): ?>
                <!-- html before -->
                <?php while ( have_rows('child-group') ) : the_row(); ?>
    
                    <?php if ( have_rows('repeater') ): ?>
                        <!-- html before -->
                        <?php while ( have_rows('repeater') ) : the_row(); ?>
    
                            <!-- item contents -->
                            <?php the_sub_field("image") ?>
                            <?php the_sub_field("title") ?>
                            <!-- item contents -->
    
                        <?php endwhile; ?>
                        <!-- html after -->
                    <?php endif; ?>
    
                <?php endwhile; ?>
                <!-- html after -->
            <?php endif; ?>
    
        <?php endwhile; ?>
        <!-- html after -->
    <?php endif; ?>
    

    请记住,have_rows() 默认为当前帖子。

    要从不同的帖子中获取行,请使用:have_rows('key', $postID);

    或者如果你使用选项页面:have_rows('key', "options");

    【讨论】:

      猜你喜欢
      • 2018-06-12
      • 2017-01-07
      • 2019-02-03
      • 2019-12-19
      • 2020-12-19
      • 2019-03-30
      • 2014-07-17
      • 2013-12-29
      • 2014-03-03
      相关资源
      最近更新 更多