2017-10-21 242 views
0

我目前将ACF字段添加到我的猫头鹰传送带中。获取图像以显示作品。我遇到了一个问题,我的代码将所有来自中继器的结果分散到每张幻灯片中,而不是一个接一个。以下是代码(所有内容都正确链接到Wordpress ACF字段),并附上了滑块外观的图像。ACF Gallery中的ACF转发器呈现不正确

关于如何解决这个问题的任何建议?

<div class="owl-carousel" id="owl-single-example"> 
<?php foreach ($homepage_slideshow_gallery as $homepage_slideshow_gallery):?> 
    <div class="slide" style="background-image: url('<?php echo $homepage_slideshow_gallery['url']; ?>')" /> 
     <div class="container caption"> 

     <?php if(have_rows('homepage_slideshow_repeater')): ?> 
      <?php while(have_rows('homepage_slideshow_repeater')): the_row(); ?> 
      <p><?php the_sub_field('homepage_slideshow_repeater_company'); ?></p> 
      <h1 class="textblock"><span><?php the_sub_field('homepage_slideshow_repeater_title'); ?></h1> 
      <a class="btn" href="<?php the_sub_field('homepage_slideshow_repeater_url'); ?>">View Work</a> 
      <?php endwhile; ?> 
     <?php endif; ?> 

     </div> 
    </div> 
<?php endforeach;?> 

The error where all results from the repeater (Company name, title and URL) all get spit out into each slide, rather than one by one.

+1

猫头鹰的正确结构是什么?你将所有内容都放入一个幻灯片中的同一个容器中......是它期望的吗? – FluffyKitten

+0

@FluffyKitten这是我认为我会出错的地方。我如何构造代码,以便中继器能够为每个幻灯片吐出一个结果? –

+1

这取决于猫头鹰!你有没有检查猫头鹰的文件和例子,看看它的期望?另外,我不了解ACF字段的结构 - 您的中继器字段与滑块图像有什么关系?目前没有明确的联系......或者它们是完全独立的吗? – FluffyKitten

回答

1

有自己的图像和字幕之间没有直接的关系,因为它们是在不同的ACF领域,所以你已经对自己更难以让您的循环权利建立该关联正确。

我的建议是直接将图像字段添加到您的中继器字段中,而不是使用单独的图库字段。

1:编辑具有中继器的现场组,并添加另一个子给它的形象,具有以下设置:

  • 字段类型:内容:图片

  • 返回值:图像URL

通过仅返回图片网址,我们可以直接将其用于背景图片网址。

2:接下来编辑您的主页和相应的滑块的图像添加到您的中继器沿侧直接的标题,标题等

3:现在在你的代码,你只需要一次循环,因为所有的相关信息在同一个中继器行中。你可以使用这样的事情(使用字段名“slide_image”为图片):

<?php if(have_rows('homepage_slideshow_repeater')): ?> 
    <div class="owl-carousel" id="owl-single-example"> 
    <?php while(have_rows('homepage_slideshow_repeater')): the_row(); ?> 

     /* get the image from the repeater - the content will be just the url so we can use it directly */ 
     <div class="slide" style="background-image: url('<?php the_sub_field('slide_image'); ?>')" /> 

      /* now add the caption etc for this image to the slide */ 
      <div class="container caption"> 
      <p><?php the_sub_field('homepage_slideshow_repeater_company'); ?></p> 
      <h1 class="textblock"><span><?php the_sub_field('homepage_slideshow_repeater_title'); ?></h1> 
      <a class="btn" href="<?php the_sub_field('homepage_slideshow_repeater_url'); ?>">View Work</a>  
      </div> 
     </div> 

    <?php endwhile; ?> 
    </div> 
<?php endif; ?> 

请注意,这只是我的头顶部&是未经测试,但它应该给你最新的想法需要。