This is an extension of a question I previously asked here in the forum. I would like to set up a slider which lets the user cycle through all the images of a project, while only the first image of each project is being displayed on the homepage itself. The slider should appear on top of the entire page (rather than loading a separate page for each project which contains the slider) once the user clicks on a project’s image.
The forum kindly recommended my a variety of slider plugins to accomplish this. I am working with the Fancybox slider (http://fancyapps.com/fancybox/3/). I have managed to set up the slider successfully, it is now part of my showcase-snippet. The part of the snippet which enables the slider looks like this:
This works in so far as it loads the first image of a project, puts it into my grid (on the homepage) and lets the user click on in to open the fancybox-slider. What it doesn’t do yet, is load the other images which were put into the project in the panel. How can I do that? The homepage should continue to only display the first image of each project but with the slider the user is supposed to be able to cycle through all images of each respective project.
Hm, I think it would be better not to load all images at once and then hide them visually, but only load them if someone clicks on the link to the next image.
I did make some progress loading the images via $project->images(). I’m declaring a variable first in my snippet:
<?php
$projectImages = $project->images();
?>
Then I use it to create links for the fancybox-slider to cycle through. I also call a thumbnail of the each project to be displayed on the homepage itself. Only issue now is, that when I open the slider by clicking on any image of any project, that slider cycles through ALL images of all projects instead of only the images of the respective project which the clicked image belongs to. This is the current version of my snippet:
<?php // no need to open up php tags many times
foreach($projects as $project):
// what's the sense of using $projectImages once..
$projectImages = $project->images();
?>
// you can just use $image right away
$thumb = $image;
// this should resolve in no display as nothing between "a" has been declared
<a href="<?php echo $image->url() ?>" data-fancybox="images"></a>
You first get the first image, then you loop through all images, so in your example above, you would have to exclude the first image from the image loop.
foreach($projectImages->not($image) as $img):
Here is a working alternative (including a counter for each group: data-fancybox="gallery-<?= $projects->indexOf($project) ?>"):
Only issue now is that the custom option which I had set up for the fancybox-slider don’t apply anymore to the slider which is opened upon clicking the images. I had set it up like this:
Do you know by any chance how to simply set the options for the fancybox-slider globally for the entire site so they apply to all future sliders on the site?
EDIT: Found out that global options can be set for fancybox by calling the default settings and changing them for the entire instance, like this: