WordPress Lightbox问题

rryofs0p  于 5个月前  发布在  WordPress
关注(0)|答案(1)|浏览(71)

我遇到了一个lightbox的问题,我似乎不能把我的手指放在上面。当lightbox打开时,它加载的帖子/页面作为第一张幻灯片,而不是画廊中的图像。我还在代码块中的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; ?>

字符串

7xllpg7q

7xllpg7q1#

这里有一个修改后的代码,你应该尝试

<?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; ?>

字符串

相关问题