我已经在我的网站上部分成功地集成了引导图像库(http://blueimp.github.io/Bootstrap-Image-Gallery/),但是如果我在页面上发布了多个图库/文章,点击图像并且lightbox会打开所有图像每个画廊的。我想要的是灯箱只是循环点击特定画廊的图像。Bootstrap Image Gallery显示来自多个画廊的所有图像。只想显示特定的图库图像
我可以通过为每个图库硬编码HTML并设置适当的ID等来实现我想要的效果,但是我想使用Wordpress图库小部件来添加图库并使灯箱正常工作。
我在Wordpress上使用了根框架基础主题,并且玩过了gallery.php文件,但无济于事。在gallery.php
文件中有一个roots_gallery
函数,该函数的一部分根据图库的帖子ID创建一个div类ID,然后还为该图库指定一个唯一的编号ID。从gallery.php
文件代码行是如下:
$unique = (get_query_var('page')) ? $instance . '-p' . get_query_var('page'): $instance;
$output = '<div class="gallery gallery-' . $id . '-' . $unique . '">';
在同一gallery.php
文件有一个roots_attachment_link_class
函数,它使用str_replace
功能,以改变各像册的图像的标签,如下添加缩略图类:
function roots_attachment_link_class($html) {
$postid = get_the_ID();
$html = str_replace('<a', '<a class="thumbnail img-thumbnail"', $html);
return $html;
}
add_filter('wp_get_attachment_link', 'roots_attachment_link_class', 10, 1);
达到我想要什么,我只需要一个data-gallery
属性添加到对应于相同的画廊ID,像这样的上述str_replace
功能:
$html = str_replace('<a', '<a class="thumbnail img-thumbnail" data-gallery=".blueimp-gallery-[gallery ID], $html);
我可以用得到的画廊ID的第一部分没有问题:
$id = get_the_ID();
但我不能让这在roots_gallery
函数创建的$unique
ID部分。我曾经尝试这样做:
$id = get_the_ID();
static $instance = 0;
$instance++;
$unique = (get_query_var('page')) ? $instance . '-p' . get_query_var('page'): $instance;
$html = str_replace('<a', '<a class="thumbnail img-thumbnail" data-gallery=".blueimp-gallery-' .$id . '-' . $unique . '"', $html);
return $html;
的$instance
部分在roots_gallery
函数中使用,但在这里它提供了一个唯一的ID对每个图像意味着灯箱展示只是一个图像。
我不是专家的PHP编码器,所以这可能是基本的东西,但我一直在挠我的头一阵子,所以任何帮助,非常感谢。如有必要,我可以提供完整的gallery.php
文件。
感谢