Skip to content

Instantly share code, notes, and snippets.

@ryanjbonnell
Created February 27, 2012 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ryanjbonnell/1926630 to your computer and use it in GitHub Desktop.
Save ryanjbonnell/1926630 to your computer and use it in GitHub Desktop.
jQuery Vegas Plugin output for WordPress
<?php if(get_field('slideshow')): ?>
<script src="<?php bloginfo('template_directory') ?>/js/jquery.vegas-1.2.min.js"></script>
<script>
jQuery(document).ready(function ($) {
$.vegas('slideshow', {
step: 0,
delay: 5000,
backgrounds: [
<?php
$array = get_field('slideshow');
$first_element = array_shift(array_keys($array));
$last_element = end(array_keys($array));
$indent = "\n\t\t\t\t\t\t";
foreach ($array as $key => $value) {
if ($key === $first_element) {
echo $indent . "{ src: '" . $value[photo] . "', fade: 500 }, ";
} else if ($key == $last_element) {
echo $indent . "{ src: '" . $value[photo] . "', fade: 500 } \n";
} else {
echo $indent . "{ src: '" . $value[photo] . "', fade: 500 }, ";
}
}
?>
],
preload: false
});
});
</script>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment