WP ACF 获取滑块中图像数量的附件 'Page Link' URL
WP ACF Get Attachment 'Page Link' URL on number of images in slider
我正在使用高级自定义字段为我的网站生成滑块。每个图像(附件)也有一个使用 'Page Link' 选项附加到它们的自定义字段,这允许我将 link 与每个图像相关联。下面的代码是通过一个 link 拉取的,但是对于每张图像都是相同的,无论滑块中显示的是哪一张(每张图像都应该有不同的 link)
<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' 自定义字段的最佳用途。相反,我转而使用可以包含 sub-fields 的 'Repeater' 字段,我可以在其中保存图像、标题和 link 信息。代码修改如下
<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>
我正在使用高级自定义字段为我的网站生成滑块。每个图像(附件)也有一个使用 'Page Link' 选项附加到它们的自定义字段,这允许我将 link 与每个图像相关联。下面的代码是通过一个 link 拉取的,但是对于每张图像都是相同的,无论滑块中显示的是哪一张(每张图像都应该有不同的 link)
<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' 自定义字段的最佳用途。相反,我转而使用可以包含 sub-fields 的 'Repeater' 字段,我可以在其中保存图像、标题和 link 信息。代码修改如下
<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>