【发布时间】:2021-01-07 23:05:09
【问题描述】:
我希望将 Alt 文本添加到滑块图像。我能够添加该行:
alt ="<?= $alt = get_post_meta(get_post_thumbnail_id($post->ID), '_wp_attachment_image_alt', true); ?>"
这条线拉入了照片的替代文字,但它与滑块中所有照片的替代文字相同。它似乎没有将每个替代文本循环到每张照片。下面是拉取图片的代码。
<?php $_gallery = get_field('project_gallery_photos'); ?>
<?php if( $_gallery ) { ?>
<div class="_featured-images">
<div class="_slider">
<?php foreach( $_gallery as $_img ): ?>
<div class="_slide">
<img src="<?= $_img['photo']['sizes']['project-images']?>" alt ="<?= $alt = get_post_meta(get_post_thumbnail_id($post->ID), '_wp_attachment_image_alt', true); ?>"/>
<?php if( $_img['photo_title'] || $_img['photo_caption'] ) { ?>
<div class="_caption">
<?= $_img['photo_title']? '<b>'.$_img['photo_title'].'</b><br>': '' ?>
<?= $_img['photo_caption'] ?>
</div>
<?php } ?>
</div>
<?php endforeach; ?>
</div>
【问题讨论】: