Skip to content

Instantly share code, notes, and snippets.

@eccentricpixel
Last active December 22, 2015 01:28
Show Gist options
  • Save eccentricpixel/6396304 to your computer and use it in GitHub Desktop.
Save eccentricpixel/6396304 to your computer and use it in GitHub Desktop.
Setup a loop in php to get your array of values and then echo those values inside of backstretch or other js functions. Below is an example of using PODS to pull a marquee image from a CPT created with Pods. While you can use php directly inside your script tag, the js functionality will not work properly; for instance, in the case of Backstretc…
<?php
$counter = 0;
$marqueesParams = array('limit'=> 20);
$marquees = pods('marquee');
$marquees->find($marqueesParams);
if (0 < $marquees->total()){
while ($marquees->fetch()) {
$artwork = $item->field('marquee_artwork');
foreach($artwork as $art) {
$artwork_js .= "\"".$art['guid']."\", ";
}
}
}
?>
<script>jQuery(document).ready(function($){
$.backstretch([<?=$artwork_js?>], {duration: 13000, fade: 750});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment