I am looking to create a slider that uses ACF to display a separate slider on each individual page that has its own images loaded into the gallery field.
I have currently created the slider using flexslider, and have managed to get the images to display, but the problem I have is all the images are displaying on each page that has an image set. So page 1 has image 1 and this only displays on page 1 (no other pages) which is what I want. However, if I add an image to page 2, the page 1 and page 2 both display the slider with image 1 and 2. I need to have separate slide images for each individual page, andI need the slider to not display if no images are set on a page. I hope that all makes sense. This is the code I have so far:
<div id="featured" class="flexslider clearfix"> <ul class="slides"> <?php $args = array( 'post_type' => 'page', ); $the_query = new WP_Query($args); ?> <?php if (have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); ?> <?php $images = get_field('slider_image'); if ($images): ?> <?php foreach ($images as $image): ?> <li> <img src="<?php echo $image['url']; ?>"> </li> <?php endforeach; ?> <?php endif; ?> <?php endwhile; endif;?> </ul> </div>
Any help would be really appreciated. I'm guessing I need to loop pages by id or something, but I'm pretty new to PHP so I'm not entirely sure. Thanks