Wordpress -高级自定义域库

9avjhtql  于 2022-11-02  发布在  WordPress
关注(0)|答案(2)|浏览(237)

我正在使用ACF插件,我创建了一个灵活的内容来显示标题,内容和画廊,但我不能得到的图像。
我的代码是:

<div id="services-pages">
  <?php
    if( have_rows('serviços') ):
      while ( have_rows('serviços') ) : the_row();
      ?>

      <div class="container">
        <div class="row">
          <div class="col-xs-12 col-sm-12 col-md-12">
            <div class="row">
              <div class="col-xs-12 col-sm-12 col-md-6">
                <div class="content">
                  <div class="title">
                    <hr>
                    <span><?php echo the_sub_field('title');?></span>
                  </div>
                  <div class="info">
                    <p><?php echo the_sub_field('content');?></p>
                  </div>
                </div>
              </div>
              <div class="col-xs-12 col-sm-12 col-md-6">
                <div class="row images">
                  <?php
                    $images = the_sub_field('images');
                    var_dump($images);

                  ?>
                  <div class="col-xs-12 col-sm-12 col-md-12">
                    <div class="slider-service-element">
                      <?php foreach( $images as $image ): ?>
                        <div>
                          <img src="<?php echo $image['url']; ?>" />
                        </div>
                       <?php endforeach; ?>
                    </div>
                  </div>
                  <div class="col-xs-12 col-sm-12 col-md-12">
                    <div class="slider-service-main">
                      <?php foreach( $images as $image ): ?>
                        <div>
                          <img src="<?php echo $image['url']; ?>" />
                        </div>
                       <?php endforeach; ?>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
        <?php
        endwhile;
    else :
    ?>
    <div>
      <span>no records</span>
    </div>
    <?php
    endif;
  ?>
</div>

我的ACF字段:

我已经试着用get_field()the_sub_field()得到画廊了。我该怎么解决这个问题呢?

  • 谢谢-谢谢
fxnxkyjh

fxnxkyjh1#

试试这个

$images = get_sub_field('images');

if( $images ):
    foreach( $images as $image ):
        ?><img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" /><?php
    endforeach;
endif;

在acf论坛上有一个关于它的帖子
https://support.advancedcustomfields.com/forums/topic/gallery-field-within-a-repeater-field/

j2qf4p5b

j2qf4p5b2#

<?php if( have_rows('glp_images') ):
// loop through the rows of data
while ( have_rows('glp_images') ) : the_row();

    $images = get_sub_field('glp_img');
    if( $images ): ?>

    <?php foreach( $images as $image ): ?>
        <div>
            <img src="<?php echo $image; ?>" alt="" />
        </div>
    <?php endforeach; endif;?>
<?php endwhile; endif; ?>

相关问题