Hi everyone, this topic has been done before, but not the way I am trying to do it. Here is a link to the page I am working on: https://new.pyrographix.co.za/category/projects/live-video-production/
The video popups are basically what I am trying to achieve but no need for the sliding arrows once you are in the popup: http://www.refreshanimation.com/
I have managed to create a script that closes the popup and stops the video playing:
$(‘.close’).click(function(e) {
e.preventDefault();
$(‘.video-embed’).children(‘iframe’).attr(‘src’, ‘’);
$(‘.popup-overlay’).addClass(‘display-none’);
});
$(‘a#video-button’).click(function(){
$(‘.popup-overlay’).removeClass(‘display-none’);
$(‘.video-embed’).children(‘iframe’).attr(‘src’, ‘YouTube’);
});
But, I need to have a dynamic link where the youtube link is, and the link is being drawn from a ACF custom field in Wordpress and looks like this:
<?php the_field('pop_up_video'); ?>When I put that link in, it is not dynamically going through the posts and choosing the right link for the button you just clicked, it is only ever choosing the last video link of the loop of posts and showing that one for all the popups.
How can I make it iterate through? Here is my whole code for this piece:
<div class="project-box">
<div id="close<?php the_permalink() ?>"></div>
<div class="project-box-image">
<div class="project-box-overlay">
<div class="project-overlay-links">
<a id="video-button" href="#<?php the_title(); ?>" class="button-link">Play video</a>
<a class="button-link" href="<?php the_permalink() ?>">View Project</a>
</div><!---project-overlay-links-->
</div><!---project-box-overlay-->
<div id="<?php the_title(); ?>" class="popup-overlay">
<div id="popup" class="popup">
<a class="close" href="#close<?php the_permalink() ?>">×</a>
<div class="content">
<?php if( get_field('pop_up_video') ): ?>
<div class="video-embed" >
<iframe width="800" height="400" src="<?php the_field('pop_up_video'); ?>?autoplay=0&rel=0" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div><!---video-embed-->
<?php endif; ?>
<script>
$('.close').click(function(e) {
e.preventDefault();
$('.video-embed').children('iframe').attr('src', '');
$('.popup-overlay').addClass('display-none');
});
$('a#video-button').click(function(){
$('.popup-overlay').removeClass('display-none');
$('.video-embed').children('iframe').attr('src', '<?php the_field('pop_up_video'); ?>');
});
</script>
</div><!---content-->
</div><!---popup-->
</div><!---overlay-->
<?php the_post_thumbnail('service-box-image'); ?>
</div><!---project-box-image-->
<a href="<?php the_permalink() ?>">
<h5><?php the_title(); ?></h5>
</a>
<div class="post-tags">
<?php the_tags('', ', '); ?>
</div><!---post-tags-->
<p><?php the_excerpt(); ?></p>
</div><!---project-box--><?php endwhile; ?><?php endif; ?>