I have created numerous picture galleries on the same page. If I click on one gallery picture, fancybox v3.5.7 opens and you are able to click through not just this gallery but all pictures in the WP Media library.
I’d like to limit the view to the specific gallery.
How do I adjust the jQuery code to achieve this?
I know how to give each gallery a class, but where do I put this jQuery code?
With this jQuery line I activate fancybox-3 for WordPress:
$( "a[href$='.jpg'], a[href$='.jpeg'], a[href$='.png'], a[href$='.gif']" ) . attr( 'data-fancybox', 'gallery' ) . fancybox({
buttons: [
"zoom",
//"share",
//"slideShow",
"fullScreen",
//"download",
//"thumbs", // blendet Buttons für Thumbnails ein
"close"
],
(and so on)
});
2
Answers
From Fancybox’s own documentation:
With this code snippet:
you are creating one gallery that contains all elements matching your selector.
To create separate galleries, choose different values for
data-fancybox
attribute.You can, for example, loop through each gallery, find all links and set the appropriate
data-fancybox
value.