107 lines
5.0 KiB
PHP
107 lines
5.0 KiB
PHP
<?php
|
||
|
||
/**
|
||
* Преподаватели — карточки (основной блок)
|
||
* CPT teacher + CF: направление, бейдж, аватар, год начала, образование,
|
||
* доп. образование, личная фраза, оценка, категория для фильтра.
|
||
*
|
||
* @package Dekart
|
||
*/
|
||
|
||
if (! defined('ABSPATH')) {
|
||
exit;
|
||
}
|
||
|
||
$teachers_args = array(
|
||
'posts_per_page' => -1,
|
||
'orderby' => 'date',
|
||
'order' => 'ASC',
|
||
'post_type' => 'teacher',
|
||
'post_status' => 'publish',
|
||
'no_found_rows' => true,
|
||
'update_post_meta_cache' => true,
|
||
'update_post_term_cache' => true,
|
||
);
|
||
|
||
$teachers_list = get_posts($teachers_args);
|
||
if (empty($teachers_list)) {
|
||
return;
|
||
}
|
||
|
||
$current_year = (int) current_time('Y');
|
||
?>
|
||
<section class="teachers-cards section-bg reveal" data-bg="teachers-cards" aria-label="Преподаватели школы">
|
||
<div class="container">
|
||
<div class="teachers-cards__grid" id="teachers-grid">
|
||
<?php foreach ($teachers_list as $teacher) :
|
||
setup_postdata($teacher);
|
||
|
||
$tid = (int) $teacher->ID;
|
||
$full_name = get_the_title($tid);
|
||
$cat = carbon_get_post_meta($tid, 'teacher_category');
|
||
$direction = carbon_get_post_meta($tid, 'teacher_direction');
|
||
$badge = carbon_get_post_meta($tid, 'teacher_badge');
|
||
$start_year = carbon_get_post_meta($tid, 'teacher_start_year');
|
||
$rating = carbon_get_post_meta($tid, 'teacher_rating');
|
||
$avatar_id = carbon_get_post_meta($tid, 'teacher_avatar');
|
||
$avatar_url = $avatar_id ? wp_get_attachment_url($avatar_id) : '';
|
||
$alt_text = $avatar_id ? get_post_meta($avatar_id, '_wp_attachment_image_alt', true) : $full_name;
|
||
|
||
$tenure = '';
|
||
if ($start_year && absint($start_year) > 1900) {
|
||
$tenure = max(0, (int) $current_year - (int) $start_year);
|
||
}
|
||
|
||
$cat_filter = ! empty($cat) ? $cat : 'all';
|
||
?>
|
||
<article class="teachers-card reveal" data-category="<?php echo esc_attr($cat_filter); ?>">
|
||
<div class="teachers-card__media">
|
||
<?php if ($avatar_url) : ?>
|
||
<img class="teachers-card__photo" loading="lazy" decoding="async"
|
||
src="<?php echo esc_url($avatar_url); ?>"
|
||
alt="<?php echo esc_attr($alt_text); ?>"
|
||
width="480" height="480">
|
||
<?php endif; ?>
|
||
<?php if ($badge) : ?>
|
||
<span class="teachers-card__badge"><?php echo esc_html($badge); ?></span>
|
||
<?php endif; ?>
|
||
</div>
|
||
|
||
<div class="teachers-card__body">
|
||
<h3 class="teachers-card__name"><?php echo esc_html($full_name); ?></h3>
|
||
|
||
<?php if ($direction) : ?>
|
||
<div class="teachers-card__direction"><?php echo esc_html($direction); ?></div>
|
||
<?php endif; ?>
|
||
|
||
<?php if ($tenure) : ?>
|
||
<div class="teachers-card__tenure">Стаж: <strong><?php echo esc_html($tenure); ?></strong> лет</div>
|
||
<?php endif; ?>
|
||
|
||
<?php $rating_num = (float) $rating; ?>
|
||
<?php if ($rating_num > 0) : ?>
|
||
<div class="teachers-card__rating" aria-label="Оценка: <?php echo esc_attr($rating_num); ?> из 5">
|
||
<span class="teachers-card__stars" aria-hidden="true">
|
||
<?php for ($s = 1; $s <= 5; $s++) : ?>
|
||
<svg class="teachers-card__star<?php echo $s <= round($rating_num) ? ' is-filled' : ''; ?>" width="16" height="16" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true"><path d="M10 1l2.39 4.84 5.34.78-3.87 3.77.92 5.34L10 13.27l-4.78 2.51.92-5.34L2.27 6.6l5.34-.78L10 1z"/></svg>
|
||
<?php endfor; ?>
|
||
</span>
|
||
<span class="teachers-card__rating-num"><?php echo esc_html(rtrim(rtrim(number_format($rating_num, 1), '0'), '.')); ?></span>
|
||
</div>
|
||
<?php endif; ?>
|
||
|
||
<div class="teachers-card__actions">
|
||
<a class="teachers-card__btn btn-write open-bitrix-form" href="#" onclick="return false;">
|
||
Записаться к <?php echo esc_html(mb_strtolower($full_name)); ?>
|
||
</a>
|
||
<a class="teachers-card__link" href="<?php echo esc_url(get_permalink($tid)); ?>">
|
||
Подробнее о преподавателе →
|
||
</a>
|
||
</div>
|
||
</div>
|
||
</article>
|
||
<?php endforeach;
|
||
wp_reset_postdata(); ?>
|
||
</div>
|
||
</div>
|
||
</section>
|