Skip to content

Instantly share code, notes, and snippets.

@kbjr
Last active December 15, 2015 05:39
Show Gist options
  • Save kbjr/5210793 to your computer and use it in GitHub Desktop.
Save kbjr/5210793 to your computer and use it in GitHub Desktop.
<?php while (have_posts()) : the_post(); $count++; ?>
<?php $video = get_field('video'); ?>
<a href="#" onclick="switchVideo(this, '<?php echo $video; ?>'); return false;" class="vidtn">
<img src="<?php echo the_field('vidthumbnail'); ?>" />
</a>
<?php endwhile; ?>
<script type="text/javascript">
//
// @param original the DOM element of the existing video to be replaced
// @param newVideo the video that we are inserting in place of the original
// @return jQuery a jQuery object containing the new video element
//
function switchVideo(original, newVideo) {
var $newElem = $('<iframe width="853" height="480" src="http://www.youtube.com/embed/' + newVideo +
'?rel=0" frameborder="0" allowfullscreen></iframe>');
$newElem.replaceAll(original);
return $newElem;
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment