我已經在我的網站上部分成功地集成了引導圖像庫(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
文件。
感謝