107 lines
3.8 KiB
PHP
107 lines
3.8 KiB
PHP
<?php
|
|
/**
|
|
* Секция «Отзывы» страницы класса начальной школы.
|
|
* Вкладка «💬 Отзывы»: выбор из CPT reviews (association).
|
|
* Пусто — последние отзывы школы (тип school/primary).
|
|
*
|
|
* @package Dekart
|
|
*/
|
|
|
|
if (! defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
$post_id = (int) get_the_ID();
|
|
|
|
$reviews_title = crb_get_post_meta($post_id, 'class_reviews_title', 'Отзывы родителей');
|
|
$reviews_sel = crb_get_post_meta($post_id, 'class_reviews');
|
|
|
|
$review_ids = array();
|
|
if (is_array($reviews_sel) && ! empty($reviews_sel)) {
|
|
foreach ($reviews_sel as $r_id) {
|
|
$r_id = (int) $r_id;
|
|
if ($r_id > 0) {
|
|
$review_ids[] = $r_id;
|
|
}
|
|
}
|
|
}
|
|
|
|
$args = array(
|
|
'post_type' => 'reviews',
|
|
'post_status' => 'publish',
|
|
'posts_per_page' => 3,
|
|
'orderby' => 'date',
|
|
'order' => 'DESC',
|
|
'no_found_rows' => true,
|
|
);
|
|
|
|
if (! empty($review_ids)) {
|
|
$args['post__in'] = $review_ids;
|
|
$args['orderby'] = 'post__in';
|
|
$args['posts_per_page'] = count($review_ids);
|
|
} else {
|
|
$args['meta_query'] = array(
|
|
array(
|
|
'key' => 'review_type',
|
|
'value' => array('school', 'primary'),
|
|
'compare' => 'IN',
|
|
),
|
|
);
|
|
}
|
|
|
|
$reviews_query = new WP_Query($args);
|
|
|
|
if (! $reviews_query->have_posts()) {
|
|
return;
|
|
}
|
|
|
|
$star_svg = '<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/></svg>';
|
|
?>
|
|
|
|
<section class="class-testimonials section-bg" data-bg="class-testimonials" id="class-testimonials" aria-labelledby="class-testimonials-title">
|
|
<div class="container">
|
|
|
|
<div class="section-header--left">
|
|
<h2 id="class-testimonials-title" class="bento-h2"><?php echo esc_html($reviews_title); ?></h2>
|
|
</div>
|
|
|
|
<div class="class-testimonials__grid">
|
|
<?php
|
|
while ($reviews_query->have_posts()) :
|
|
$reviews_query->the_post();
|
|
$review_post_id = (int) get_the_ID();
|
|
|
|
$review_text = carbon_get_post_meta($review_post_id, 'review_text');
|
|
$review_star = carbon_get_post_meta($review_post_id, 'review_star');
|
|
$review_avatar = carbon_get_post_meta($review_post_id, 'review_avatar');
|
|
$author = get_the_title($review_post_id);
|
|
|
|
if (empty($review_text)) {
|
|
continue;
|
|
}
|
|
$star_count = max(1, min(5, (int) ($review_star ?: 5)));
|
|
?>
|
|
<article class="class-testimonials__card">
|
|
<div class="class-testimonials__stars" aria-label="Оценка: <?php echo esc_attr($star_count); ?> из 5">
|
|
<?php echo str_repeat($star_svg, $star_count); ?>
|
|
</div>
|
|
<blockquote class="class-testimonials__text">“<?php echo esc_html(wp_trim_words($review_text, 38, '…')); ?>”</blockquote>
|
|
<footer class="class-testimonials__author">
|
|
<?php if ($review_avatar) :
|
|
$avatar_url = wp_get_attachment_image_url((int) $review_avatar, 'thumbnail');
|
|
if ($avatar_url) : ?>
|
|
<img class="class-testimonials__avatar" src="<?php echo esc_url($avatar_url); ?>" alt="" loading="lazy" width="48" height="48">
|
|
<?php endif;
|
|
endif; ?>
|
|
<cite class="class-testimonials__name"><?php echo esc_html($author); ?></cite>
|
|
</footer>
|
|
</article>
|
|
<?php
|
|
endwhile;
|
|
wp_reset_postdata();
|
|
?>
|
|
</div>
|
|
|
|
</div>
|
|
</section>
|