carousel.php
2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?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>