carousel.php 2.5 KB
<?php

/**
 * Carousel Block Template.
 *
 * @param   array $block The block settings and attributes.
 * @param   string $content The block inner HTML (empty).
 * @param   bool $is_preview True during AJAX preview.
 * @param   (int|string) $post_id The post ID this block is saved to.
 */

// Create id attribute allowing for custom "anchor" value.
$id = 'carousel-' . $block['id'];
if (!empty($block['anchor'])) {
    $id = $block['anchor'];
}

// Create class attribute allowing for custom "className" and "align" values.
$className = 'carousel';
if (!empty($block['className'])) {
    $className .= ' ' . $block['className'];
}
if (!empty($block['align'])) {
    $className .= ' align' . $block['align'];
}
if ($is_preview) {
    $className .= ' is-admin';
}

$carousel_style = get_field('carousel_style');

?>
<div id="<?php echo esc_attr($id); ?>" class="<?php echo esc_attr($className); ?> ">
    <?php
    $args = array(
        'post_type' => 'testimonial', // Replace 'testimonial' with your custom post type
        'posts_per_page' => -1
    );
    $testimonial_query = new WP_Query($args);
    if ($testimonial_query->have_posts()): ?>
        <div class="testimonials-carousel carousel-items <?php echo $size; ?>">
            <div class='swiper-wrapper'>
                <?php while ($testimonial_query->have_posts()):
                    $testimonial_query->the_post(); ?>
                    <div class="swiper-slide">
                        <div class="testimonials">
                            <div class="testimonial-text">
                                <div class="row">
                                    <div class="col-md-2 quotes col-sm-12">
                                    </div>
                                    <div class="testimonial-copy col-md-10 col-sm-12">
                                        <?php the_content(); ?>
                                        <div class="testimonial-author"><?php the_title(); ?></div>
                                    </div>
                                </div>

                            </div>
                        </div>
                    </div>
                <?php endwhile;
                wp_reset_postdata(); ?>
            </div>
            <div class="swiper-pagination"></div>
            <div class="swiper-button-prev" data-id="<?php echo esc_attr($id); ?>"></div>
            <div class="swiper-button-next" data-id="<?php echo esc_attr($id); ?>"></div>
        </div>
    <?php else: ?>
        <p>Please add some slides.</p>
    <?php endif; ?>
</div>