WP ACF获取附件';页面链接';滑块中图像数量的URL


WP ACF Get Attachment 'Page Link' URL on number of images in slider

我正在使用高级自定义字段为我的网站生成滑块。每个图像(附件)还使用"页面链接"选项附加了一个自定义字段,允许我将链接与每个图像关联起来。下面的代码通过一个链接,但对于每个图像都是相同的,无论滑块中显示的是哪一个(每个图像都应该有不同的链接)

    <section class="slideshow">
        <?php 
        $images = get_field('slideshow');
        if( $images ):
        ?>
            <?php foreach( $images as $image ): ?>
                <figure>
                    <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
                    <figcaption>
                        <h2><?php echo $image['caption']; ?></h2>
                        <h4><a href="<?php the_field('url_link'); ?>">View Case Study</a></h4>
                    </figcaption>
                </figure>
            <?php endforeach; ?>
        <?php endif; ?>
    </section>

我还尝试将url_link字段设置为特定于图像的字段,如下所示,但这不会提取任何信息。

<h4><a href="<?php echo $image['url_link']; ?>">View Case Study</a></h4>

非常感谢。

事实证明,这并不是"Gallery"自定义字段的最佳用途。相反,我转而使用"中继器"字段,它可以有子字段,我可以在其中保存图像、标题和链接信息。法典修订如下。

<section class="slideshow">       
    <?php if( have_rows('slideshow_slides') ): ?>
        <?php while( have_rows('slideshow_slides') ): the_row(); 
            // vars
            $image = get_sub_field('image');
            $caption = get_sub_field('caption');
            $link = get_sub_field('link');
        ?>
        <figure>
            <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" />
            <figcaption>
                <h2><?php echo $caption; ?></h2>
                <?php if( $link ): ?>                    
                    <h4><a href="<?php echo $link; ?>">View Case Study</a></h4>
                <?php endif; ?>
            </figcaption>
        </figure>
        <?php endwhile; ?>
    <?php endif; ?>
</section>