Wordpress Lightbox 问题

问题描述 投票:0回答:1

我的灯箱有问题,我似乎无法将手指放在上面。当灯箱打开时,它会将帖子/页面加载为第一张幻灯片,而不是图库中的图像。我还在代码块内的 foreach 语句上收到了无效参数,这是没有意义的。

我希望通过单击按钮调用灯箱,它会打开,但将页面显示为第一张幻灯片。

当图库显示在页面上时,灯箱会正确打开。

请参阅此处的示例https://catm27.sg-host.com/horse/etro-pa/

任何帮助表示赞赏

<?php $gallery = get_field('images')[0]; ?>
   <?php if ($gallery) : ?>
      <a href="#" class="gallery_trigger btn btn-primary" data-toggle="lightbox" data-gallery="gallery-<?php the_ID(); ?>">Gallery</a>
             <div class="hidden gallery">
                  <?php foreach ($gallery['images'] as $image) : ?>    
                         <a href="<?php echo esc_url($image['url'])  ?>" class="noo-lightbox-item" data-gallery="gallery-<?php the_ID(); ?>">
                          <img src="<?php echo isset($image['sizes']['thumbnail']) ? esc_url($image['sizes']['thumbnail']) : esc_url($image['url']); ?>" alt="<?php echo isset($image['alt']) ? $image['alt'] : ''; ?>"/>
                            </a>
                  <?php endforeach; ?>
             </div>
  <?php endif; ?>
wordpress lightbox
1个回答
0
投票

这是修改后的代码

<?php 
$gallery = get_field('images');
if ($gallery && is_array($gallery)) :
    $first_gallery_item = $gallery[0];
?>
    <a href="#" class="gallery_trigger btn btn-primary" data-toggle="lightbox" data-gallery="gallery-<?php the_ID(); ?>">Gallery</a>
    <div class="hidden gallery">
        <?php foreach ($first_gallery_item['images'] as $image) : ?>    
            <a href="<?php echo esc_url($image['url'])  ?>" class="noo-lightbox-item" data-gallery="gallery-<?php the_ID(); ?>">
                <img src="<?php echo isset($image['sizes']['thumbnail']) ? esc_url($image['sizes']['thumbnail']) : esc_url($image['url']); ?>" alt="<?php echo isset($image['alt']) ? $image['alt'] : ''; ?>"/>
            </a>
        <?php endforeach; ?>
    </div>
<?php endif; ?>
© www.soinside.com 2019 - 2024. All rights reserved.