Home › Forums › Add-ons › Gallery Field › ACF Gallery and Backstrech › Reply To: ACF Gallery and Backstrech
Thanks @James
I am not a programmer and I don’t really understand how this can be done.
The main problem for me is how to get an array of image URLs from the gallery field (it is part of a Options page) and how to make them a variable. I checked how a WP gallery shortcode is done https://www.advancedcustomfields.com/resources/gallery/ but instead of the IDs I need the URL. I also tried using implode to add commas between values, but couldn’t make it work.
Could you please guide me into the right direction to solve this??
My not-working code is below. Thanks!
<!-- trying to get the array of URLs -->
<?php
$images = get_field('slideshow_gallery', 'option');
if( $images ):
foreach( $images as $image ): ?>
<?php echo $image['url']; ?>,
<br>
<?php endforeach; ?>
<?php endif; ?>
</div>
<!-- Put the URLs inside a div -->
<div id="dom-target" style="display: none;">
<?php
$output = "image01", "image02", "image03"; //just a test
echo htmlspecialchars($output); /* You have to escape because the result will not be valid HTML otherwise. */
?>
</div>
<!-- Put the content into a variable -->
<script>
var div = document.getElementById("dom-target");
var myData = div.textContent;
</script>
<script> /* Build backstretch slideshow */
// Duration is the amount of time in between slides,
// and fade is value that determines how quickly the next image will fade in
$.backstretch([
myData
], {
duration: 3000,
fade: 750
});
</script>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.