How do I create a link to a pop up Advanced Custom Fields lighbox gallery?












1















I'm trying to create an Advanced Custom Fields gallery in a lightbox that pops up when an icon is clicked. I've got it to the point where the lightbox finds all the images associated with the post and displays them properly when you click the icon, but the problem I'm having is it's also showing multiple icons for the gallery as well.



Sample Image



I assume this is because I have the gallery icon as part of the foreach loop, but I have no idea how to separate it. One idea I had was to simply assign unique CSS classes to the extra icons and then hide them but I was hoping for something more elegant. Can someone point me in the right direction? The code I've cobbled together is below.



 <?php 
$images = get_field('gallery_photos');
if($images): ?>
<div class="gallery">
<?php foreach( $images as $image ): ?>
<a href="<?php echo $image['url']; ?>" target="_blank" rel="lightbox" class="thumbnail">
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/camera-icon.png" width="30px" height="30px" alt="" border="0"/>
</a>
<?php endforeach; ?>
</div>
<?php endif; ?>









share|improve this question

























  • Your question isn't clear, provide visual example like link or SS

    – Ahmad Hassan
    Nov 14 '18 at 21:49











  • Sorry about that. Site site is on a dev server but I was able to add a screenshot for reference. This shows two sample product rows where one product has a lightbox gallery with 4 images. The lightbox functionality itself works fine, but there should only be one icon for the gallery and when clicked it shows 4 images, not 4 icons that show the 4 images.

    – Joey
    Nov 15 '18 at 15:05
















1















I'm trying to create an Advanced Custom Fields gallery in a lightbox that pops up when an icon is clicked. I've got it to the point where the lightbox finds all the images associated with the post and displays them properly when you click the icon, but the problem I'm having is it's also showing multiple icons for the gallery as well.



Sample Image



I assume this is because I have the gallery icon as part of the foreach loop, but I have no idea how to separate it. One idea I had was to simply assign unique CSS classes to the extra icons and then hide them but I was hoping for something more elegant. Can someone point me in the right direction? The code I've cobbled together is below.



 <?php 
$images = get_field('gallery_photos');
if($images): ?>
<div class="gallery">
<?php foreach( $images as $image ): ?>
<a href="<?php echo $image['url']; ?>" target="_blank" rel="lightbox" class="thumbnail">
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/camera-icon.png" width="30px" height="30px" alt="" border="0"/>
</a>
<?php endforeach; ?>
</div>
<?php endif; ?>









share|improve this question

























  • Your question isn't clear, provide visual example like link or SS

    – Ahmad Hassan
    Nov 14 '18 at 21:49











  • Sorry about that. Site site is on a dev server but I was able to add a screenshot for reference. This shows two sample product rows where one product has a lightbox gallery with 4 images. The lightbox functionality itself works fine, but there should only be one icon for the gallery and when clicked it shows 4 images, not 4 icons that show the 4 images.

    – Joey
    Nov 15 '18 at 15:05














1












1








1








I'm trying to create an Advanced Custom Fields gallery in a lightbox that pops up when an icon is clicked. I've got it to the point where the lightbox finds all the images associated with the post and displays them properly when you click the icon, but the problem I'm having is it's also showing multiple icons for the gallery as well.



Sample Image



I assume this is because I have the gallery icon as part of the foreach loop, but I have no idea how to separate it. One idea I had was to simply assign unique CSS classes to the extra icons and then hide them but I was hoping for something more elegant. Can someone point me in the right direction? The code I've cobbled together is below.



 <?php 
$images = get_field('gallery_photos');
if($images): ?>
<div class="gallery">
<?php foreach( $images as $image ): ?>
<a href="<?php echo $image['url']; ?>" target="_blank" rel="lightbox" class="thumbnail">
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/camera-icon.png" width="30px" height="30px" alt="" border="0"/>
</a>
<?php endforeach; ?>
</div>
<?php endif; ?>









share|improve this question
















I'm trying to create an Advanced Custom Fields gallery in a lightbox that pops up when an icon is clicked. I've got it to the point where the lightbox finds all the images associated with the post and displays them properly when you click the icon, but the problem I'm having is it's also showing multiple icons for the gallery as well.



Sample Image



I assume this is because I have the gallery icon as part of the foreach loop, but I have no idea how to separate it. One idea I had was to simply assign unique CSS classes to the extra icons and then hide them but I was hoping for something more elegant. Can someone point me in the right direction? The code I've cobbled together is below.



 <?php 
$images = get_field('gallery_photos');
if($images): ?>
<div class="gallery">
<?php foreach( $images as $image ): ?>
<a href="<?php echo $image['url']; ?>" target="_blank" rel="lightbox" class="thumbnail">
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/camera-icon.png" width="30px" height="30px" alt="" border="0"/>
</a>
<?php endforeach; ?>
</div>
<?php endif; ?>






wordpress gallery advanced-custom-fields






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 15:03







Joey

















asked Nov 14 '18 at 21:37









JoeyJoey

83




83













  • Your question isn't clear, provide visual example like link or SS

    – Ahmad Hassan
    Nov 14 '18 at 21:49











  • Sorry about that. Site site is on a dev server but I was able to add a screenshot for reference. This shows two sample product rows where one product has a lightbox gallery with 4 images. The lightbox functionality itself works fine, but there should only be one icon for the gallery and when clicked it shows 4 images, not 4 icons that show the 4 images.

    – Joey
    Nov 15 '18 at 15:05



















  • Your question isn't clear, provide visual example like link or SS

    – Ahmad Hassan
    Nov 14 '18 at 21:49











  • Sorry about that. Site site is on a dev server but I was able to add a screenshot for reference. This shows two sample product rows where one product has a lightbox gallery with 4 images. The lightbox functionality itself works fine, but there should only be one icon for the gallery and when clicked it shows 4 images, not 4 icons that show the 4 images.

    – Joey
    Nov 15 '18 at 15:05

















Your question isn't clear, provide visual example like link or SS

– Ahmad Hassan
Nov 14 '18 at 21:49





Your question isn't clear, provide visual example like link or SS

– Ahmad Hassan
Nov 14 '18 at 21:49













Sorry about that. Site site is on a dev server but I was able to add a screenshot for reference. This shows two sample product rows where one product has a lightbox gallery with 4 images. The lightbox functionality itself works fine, but there should only be one icon for the gallery and when clicked it shows 4 images, not 4 icons that show the 4 images.

– Joey
Nov 15 '18 at 15:05





Sorry about that. Site site is on a dev server but I was able to add a screenshot for reference. This shows two sample product rows where one product has a lightbox gallery with 4 images. The lightbox functionality itself works fine, but there should only be one icon for the gallery and when clicked it shows 4 images, not 4 icons that show the 4 images.

– Joey
Nov 15 '18 at 15:05












1 Answer
1






active

oldest

votes


















0














Modify your loop as below, it will run img tag only when $i=0, means only first time.



<?php 
$images = get_field('gallery_photos');
if($images): ?>
<div class="gallery">
<?php $i=0; foreach( $images as $image ) : ?>
<a href="<?php echo $image['url']; ?>" target="_blank" rel="lightbox" class="thumbnail">
<?php if( $i==0 ) : ?>
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/camera-icon.png" width="30px" height="30px" alt="" border="0"/>
<?php endif; ?>
</a>
<?php $i++; endforeach; ?>
</div>
<?php endif; ?>





share|improve this answer


























  • Thanks. For some reason the above loop gives the error: Warning: Invalid argument supplied for foreach()

    – Joey
    Nov 16 '18 at 1:17













  • I updated answer, try that..

    – Ahmad Hassan
    Nov 16 '18 at 2:08











  • It seems to work perfectly. Thank you so much!

    – Joey
    Nov 16 '18 at 4:36











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53309094%2fhow-do-i-create-a-link-to-a-pop-up-advanced-custom-fields-lighbox-gallery%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Modify your loop as below, it will run img tag only when $i=0, means only first time.



<?php 
$images = get_field('gallery_photos');
if($images): ?>
<div class="gallery">
<?php $i=0; foreach( $images as $image ) : ?>
<a href="<?php echo $image['url']; ?>" target="_blank" rel="lightbox" class="thumbnail">
<?php if( $i==0 ) : ?>
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/camera-icon.png" width="30px" height="30px" alt="" border="0"/>
<?php endif; ?>
</a>
<?php $i++; endforeach; ?>
</div>
<?php endif; ?>





share|improve this answer


























  • Thanks. For some reason the above loop gives the error: Warning: Invalid argument supplied for foreach()

    – Joey
    Nov 16 '18 at 1:17













  • I updated answer, try that..

    – Ahmad Hassan
    Nov 16 '18 at 2:08











  • It seems to work perfectly. Thank you so much!

    – Joey
    Nov 16 '18 at 4:36
















0














Modify your loop as below, it will run img tag only when $i=0, means only first time.



<?php 
$images = get_field('gallery_photos');
if($images): ?>
<div class="gallery">
<?php $i=0; foreach( $images as $image ) : ?>
<a href="<?php echo $image['url']; ?>" target="_blank" rel="lightbox" class="thumbnail">
<?php if( $i==0 ) : ?>
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/camera-icon.png" width="30px" height="30px" alt="" border="0"/>
<?php endif; ?>
</a>
<?php $i++; endforeach; ?>
</div>
<?php endif; ?>





share|improve this answer


























  • Thanks. For some reason the above loop gives the error: Warning: Invalid argument supplied for foreach()

    – Joey
    Nov 16 '18 at 1:17













  • I updated answer, try that..

    – Ahmad Hassan
    Nov 16 '18 at 2:08











  • It seems to work perfectly. Thank you so much!

    – Joey
    Nov 16 '18 at 4:36














0












0








0







Modify your loop as below, it will run img tag only when $i=0, means only first time.



<?php 
$images = get_field('gallery_photos');
if($images): ?>
<div class="gallery">
<?php $i=0; foreach( $images as $image ) : ?>
<a href="<?php echo $image['url']; ?>" target="_blank" rel="lightbox" class="thumbnail">
<?php if( $i==0 ) : ?>
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/camera-icon.png" width="30px" height="30px" alt="" border="0"/>
<?php endif; ?>
</a>
<?php $i++; endforeach; ?>
</div>
<?php endif; ?>





share|improve this answer















Modify your loop as below, it will run img tag only when $i=0, means only first time.



<?php 
$images = get_field('gallery_photos');
if($images): ?>
<div class="gallery">
<?php $i=0; foreach( $images as $image ) : ?>
<a href="<?php echo $image['url']; ?>" target="_blank" rel="lightbox" class="thumbnail">
<?php if( $i==0 ) : ?>
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/camera-icon.png" width="30px" height="30px" alt="" border="0"/>
<?php endif; ?>
</a>
<?php $i++; endforeach; ?>
</div>
<?php endif; ?>






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 16 '18 at 2:07

























answered Nov 15 '18 at 21:43









Ahmad HassanAhmad Hassan

212112




212112













  • Thanks. For some reason the above loop gives the error: Warning: Invalid argument supplied for foreach()

    – Joey
    Nov 16 '18 at 1:17













  • I updated answer, try that..

    – Ahmad Hassan
    Nov 16 '18 at 2:08











  • It seems to work perfectly. Thank you so much!

    – Joey
    Nov 16 '18 at 4:36



















  • Thanks. For some reason the above loop gives the error: Warning: Invalid argument supplied for foreach()

    – Joey
    Nov 16 '18 at 1:17













  • I updated answer, try that..

    – Ahmad Hassan
    Nov 16 '18 at 2:08











  • It seems to work perfectly. Thank you so much!

    – Joey
    Nov 16 '18 at 4:36

















Thanks. For some reason the above loop gives the error: Warning: Invalid argument supplied for foreach()

– Joey
Nov 16 '18 at 1:17







Thanks. For some reason the above loop gives the error: Warning: Invalid argument supplied for foreach()

– Joey
Nov 16 '18 at 1:17















I updated answer, try that..

– Ahmad Hassan
Nov 16 '18 at 2:08





I updated answer, try that..

– Ahmad Hassan
Nov 16 '18 at 2:08













It seems to work perfectly. Thank you so much!

– Joey
Nov 16 '18 at 4:36





It seems to work perfectly. Thank you so much!

– Joey
Nov 16 '18 at 4:36




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53309094%2fhow-do-i-create-a-link-to-a-pop-up-advanced-custom-fields-lighbox-gallery%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Error while running script in elastic search , gateway timeout

Adding quotations to stringified JSON object values