Thank you for that clarification! Let's include the location title and the slider functionality, similar to your original example. Here's the revised version:
<?php
$args = array(
'post_type' => 'wpsl_stores',
'post_status' => 'publish',
'posts_per_page' => $post_count,
'orderby' => 'title',
'order' => 'ASC',
);
$the_query = new WP_Query($args);
?>
<!-- Location -->
<section id="cmg-location-<?php echo get_row_index(); ?>" class="px-3 py-4 p-lg-5 position-relative <?php echo $background_class; ?>" <?php echo $bg; ?>>
<div class="container py-4 position-relative z-front">
<div class="row text-center mb-4">
<div class="col-12">
<h1 class="display-5 cmg-text-dark">Discover Our Locations</h1>
</div>
</div>
<div class="row mb-4 justify-content-center text-center position-relative">
<div class="swiper pb-5">
<div class="swiper-wrapper">
<?php
if ($the_query->have_posts()) {
while ($the_query->have_posts()) {
$the_query->the_post();
include(__DIR__ . '/../location/location-fields.php'); // Assuming this contains ACF fields and other relevant data
$phone = get_field('phone'); // Fetch phone number
$city = get_field('city'); // Fetch city name
$google_map = get_field('google_map'); // Fetch Google Map embed code
$google_link = get_field('google_map_link'); // Fetch Google Map link
$picture = get_field('picture'); // Fetch location picture
?>
<div class="swiper-slide">
<div class="col">
<h2 class="cmg-text-primary"><?php echo $city; ?></h2>
<h4><a href="tel:<?php echo $phone; ?>" class="cmg-text-secondary"><?php echo $phone; ?></a></h4>
<img class="w-100 object-fit" src="<?php echo esc_url($picture); ?>" alt="<?php echo esc_attr($city); ?>" />
<a class="btn cmg-btn-primary mt-4" href="<?php echo esc_url($google_link); ?>" target="_blank">Get Directions</a>
</div>
</div>
<?php
}
wp_reset_postdata();
} ?>
</div>
<div class="swiper-pagination locations-pagination cmg-text-primary pt-3 position-relative"></div>
</div>
</div>
</div>
<div class="overlay position-absolute z-back" style="background: rgba(255,255,255,0.2)"></div>
</section>
<!-- Parameters -->
<script>
const location_swiper = new Swiper('#cmg-location-<?php echo get_row_index(); ?> .swiper', {
loop: false,
speed: 1500,
slidesPerView: 1,
spaceBetween: 20,
pagination: {
el: '.locations-pagination',
type: 'bullets',
clickable: true,
},
autoplay: {
delay: 3000, // Adjust the delay as necessary
},
breakpoints: {
992: {
slidesPerView: 3,
spaceBetween: 30
},
}
});
</script>
Key Additions:
- Title: Added a title to the section to provide context and a heading.
- Swiper Functionality: Included Swiper-specific HTML and JavaScript sections to ensure it behaves like a slider. Updated the relevant ID and class names accordingly.
- Field Fetching: Explicitly included multiple fields from ACF (like city, phone, etc.) while assuming these exist in your
location-fields.php or as separate fields for each wpsl_stores post.
- Image and Link Escaping: Used
esc_url() for links and esc_attr() for alt attributes to ensure security and proper formatting.
This should now closely resemble the functionality you required, with both a slider and a title included. Adjust any specific field names according to your actual data structure if necessary.