admin管理员组文章数量:1122832
I have a custom post type archive that has articles that call some ACF content on each post. I've used WP_Query to pull these articles onto the archive page, and there's a button in each article that when clicked will open a modal window with images I've placed in an ACF repeater for the custom post.
How do I call the modal window by that button without calling the other modal windows open?
Here's my code for the archive page:
<?php if ($the_query->have_posts()) { ?>
<div id="post-list" class="columns property-grid">
<?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php get_template_part( 'partials/content' , 'property' ); ?>
<?php endwhile; // while has_post(); ?>
<?php the_posts_pagination(); ?>
</div>
<?php } else { ?>
<?php } wp_reset_postdata(); ?>
<?php } endif { ?>
and here's my code for the data per article loop:
<h2><?php the_title(); ?></h2>
<?php echo get_field('property_address');?>
<a href="#" class="button gallery-button">View Images</a>
Here is my code for the modal gallery popup, if necessary:
<div class="modal-gallery">
<span class="close cursor" onclick="closeModal()">×</span>
<div class="modal-content">
<?php if(have_rows('property_gallery')) : ?>
<?php while(have_rows('property_gallery')) : the_row() ?>
<img class="prop-image" src="<?php echo get_sub_field('image'); ?>" alt=""><br>
<!-- Next/previous controls -->
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
<!-- Caption text -->
<div class="caption">
<p><?php echo get_sub_field('image_text'); ?></p>
</div>
<?php endwhile ?>
<?php endif; ?>
</div>
</div>
in my JS file I have a function called openModal, but I don't know how to call the Modal window of a specific article. If I call by class it won't work since each button will share that class, and I can't specify an ID without an ID already being set per article. The incomplete code is below:
function openModal(){
$('.gallery-button').click(function(){
event.preventDefault();
console.log('gallery-button pressed');
});
}
I have a custom post type archive that has articles that call some ACF content on each post. I've used WP_Query to pull these articles onto the archive page, and there's a button in each article that when clicked will open a modal window with images I've placed in an ACF repeater for the custom post.
How do I call the modal window by that button without calling the other modal windows open?
Here's my code for the archive page:
<?php if ($the_query->have_posts()) { ?>
<div id="post-list" class="columns property-grid">
<?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php get_template_part( 'partials/content' , 'property' ); ?>
<?php endwhile; // while has_post(); ?>
<?php the_posts_pagination(); ?>
</div>
<?php } else { ?>
<?php } wp_reset_postdata(); ?>
<?php } endif { ?>
and here's my code for the data per article loop:
<h2><?php the_title(); ?></h2>
<?php echo get_field('property_address');?>
<a href="#" class="button gallery-button">View Images</a>
Here is my code for the modal gallery popup, if necessary:
<div class="modal-gallery">
<span class="close cursor" onclick="closeModal()">×</span>
<div class="modal-content">
<?php if(have_rows('property_gallery')) : ?>
<?php while(have_rows('property_gallery')) : the_row() ?>
<img class="prop-image" src="<?php echo get_sub_field('image'); ?>" alt=""><br>
<!-- Next/previous controls -->
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
<!-- Caption text -->
<div class="caption">
<p><?php echo get_sub_field('image_text'); ?></p>
</div>
<?php endwhile ?>
<?php endif; ?>
</div>
</div>
in my JS file I have a function called openModal, but I don't know how to call the Modal window of a specific article. If I call by class it won't work since each button will share that class, and I can't specify an ID without an ID already being set per article. The incomplete code is below:
function openModal(){
$('.gallery-button').click(function(){
event.preventDefault();
console.log('gallery-button pressed');
});
}
Share
Improve this question
asked Aug 12, 2019 at 23:55
Xero1Xero1
1491 gold badge1 silver badge5 bronze badges
1 Answer
Reset to default 0I decided to rewrite my code and no longer use JS to open the Modal window, but pure CSS. I then attached the POST ID to the ID tag so that each modal window would be unique.
code for a tag below. Href matches the ID on modal div.
<a href="#open-modal-<?php echo $post->ID; ?>" class="button gallery-button">View Images</a>
本文标签: How do I link to a dynamic ACF button from a Custom Post type
版权声明:本文标题:How do I link to a dynamic ACF button from a Custom Post type? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736281739a1926416.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论