I'm looking to achieve a image linking to a popup with each image having a unique link id. Currently only the first item links through to a popup but I need all of the images to link. Please help?
When you click the image it links to the bio for that employee but currently only the first item works?
my code:
<?php
$panelhead = $args['panelhead'];
$panelintro = $args['panelintro'];
$teamid = get_the_ID();
?>
<div class="fullcol pb-team-panel pb-padding">
<div class="midcol clearfix">
<div class="fullcol copy-wrapper clearfix">
<div class="team-intro copycol anim-target bottomfade-fm-dm">
<h3><?php echo $panelhead; ?></h3>
<p><?php echo $panelintro; ?></p>
</div>
</div>
<div class="fullcol team-grid">
<?php $recent = new WP_Query("post_type=team&posts_per_page=-1"); while($recent->have_posts()) : $recent->the_post();
$teamimg = get_field('team_image');
?>
<!-- popup start -->
<div id="overlay"></div>
<div id="popup">
<div class="popupcontrols">
<span id="popupclose">X</span>
</div>
<div class="popupcontent">
<div class="g3">
<img src="<?php echo $teamimg['url']; ?>" />
<a class="nexbtn" href="<?php the_field('team_linkedin'); ?>" taret="_blank" rel="noopener noreferrer">Follow <?php the_title(); ?> on LinkedIn</a>
</div>
<div class="g7">
<h4><?php the_title(); ?></h4>
<p><?php the_field('team_bio'); ?></p>
</div>
</div>
</div>
<!-- popup end -->
<div class="team-item anim-target bottomfade-fm-dm" id="team-item">
<a id="<?php echo $teamid ?>">
<div class="team-image bg-image rounded-box" style="background-image: url(<?php echo $teamimg['url']; ?>);">
</div>
<h4><?php the_title(); ?></h4>
<p><?php the_field('team_jobtitle'); ?></p>
</a>
</div>
<?php endwhile; wp_reset_postdata(); ?>
</div>
</div>
</div>
<script>
// Initialize Variables
var closePopup = document.getElementById("popupclose");
var overlay = document.getElementById("overlay");
var popup = document.getElementById("popup");
var link = document.getElementById("<?php echo $teamid ?>");
// Close Popup Event
closePopup.onclick = function() {
overlay.style.display = 'none';
popup.style.display = 'none';
};
// Show Overlay and Popup
link.onclick = function() {
overlay.style.display = 'inline-block';
popup.style.display = 'inline-block';
}
</script>
According to your loop, each item gets a popup (with same
idwhich should be unique per page) - and that's wrong. You should be having one popup for all that gets the values from the underlining link. Here's an example with one technique.