I am working from the code below. I need to create a script that creates an array from the stuff that is getting echo’d out at the end.
I think I am on the right track here.
The problem is I don’t know how to break out of the foreach pool to add the and some other stuff for the script. If I add it within the foreach, it will just spit it out over and over, obviously…
What’s the right way to do this?
<?php
$rows = get_field('gallery_repeater');
if( $rows ) {
foreach( $rows as $row ) {
$repeater_image = $row['repeater_image'];
$repeater_image_url = $repeater_image['url'];
$repeater_image_width_full = $repeater_image['width'];
$repeater_image_height_full = $repeater_image['height'];
$repeater_caption = $row['gallery_repeater_caption'];
$repeater_title = $row['gallery_repeater_title'];
$repeater_dl_url = $row['download_image'];
if ($repeater_caption) {
$image_caption = $repeater_caption;
}
else {
$image_caption = $repeater_image['caption'];
}
if ($repeater_dl_url){
$dl_url = $repeater_dl_url;
}
else {
$dl_url = $repeater_image_url;
}
if ($repeater_title){
$image_title = $repeater_title;
}
else {
$image_title = $repeater_image ['title'];
}
///// I need to break out and add:
<script>
var pswpElement = document.querySelectorAll('.pswp')[0];
////End break --- echo this stuff to build an array:
echo "{ src: '$repeater_image_url', w: $repeater_image_width_full,h: $repeater_image_height_full,msrc: '$repeater_image_url', title: '$image_caption' },";
///break out again and add:
// define options (if needed)
var options = {
// optionName: 'option value'
// for example:
index: 0 // start at first slide
};
////
}
}
?>