shkola/wp-content/themes/dekart/template-parts/teachers-cards.php
2026-07-23 18:13:49 +00:00

145 lines
6.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* Преподаватели (горизонтальный скролл, CPT)
*
* Reads teacher data directly from the 'teacher' custom post type.
*
* Поддерживает $args:
* - teacher_ids (int[]) — выбрать конкретных преподавателей.
* Если пусто/не передан — показываются все.
* - description (string) — текст описания под заголовком.
* Если пусто/не передан — жёсткий текст по умолчанию.
* - hide_label (bool) — скрыть бейдж «Преподаватели» над заголовком.
*
* Fields used:
* - Post title → teacher name
* - _teacher_direction → subject
* - _teacher_avatar → photo (attachment ID)
* - _teacher_badge → badge text
* - _teacher_start_year → experience calculation
* - _teacher_description → description (Дескрипшн преподавателя)
*
* @package Dekart
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// ── Parse args ─────────────────────────────────────────────
$teacher_ids = $args['teacher_ids'] ?? array();
$description = isset( $args['description'] ) ? $args['description'] : 'Каждый педагог имеет опыт работы с дошкольниками от 5 лет. Все — действующие учителя начальных классов с высшим образованием.';
$hide_label = ! empty( $args['hide_label'] );
// ── Query ──────────────────────────────────────────────────
$query_args = array(
'post_type' => 'teacher',
'posts_per_page' => -1,
'post_status' => 'publish',
);
if ( ! empty( $teacher_ids ) ) {
$query_args['post__in'] = $teacher_ids;
$query_args['orderby'] = 'post__in';
} else {
$query_args['orderby'] = 'date';
$query_args['order'] = 'DESC';
}
$teachers_query = new WP_Query( $query_args );
?>
<section class="bento teachers-cards" id="teachers" aria-label="Преподаватели">
<div class="bento__full section-header--left">
<?php if ( ! $hide_label ) : ?>
<span class="bento-label">Преподаватели</span>
<?php endif; ?>
<h2 class="bento-h2">Наши преподаватели — практикующие педагоги</h2>
<p class="bento-p"><?php echo esc_html( $description ); ?></p>
<div class="pksh-swipe-hint" aria-hidden="true">
<span class="pksh-swipe-hint__arrow">👇</span>
<span class="pksh-swipe-hint__text">Листайте, чтобы познакомиться с преподавателями</span>
</div>
</div>
<div class="bento__full">
<div class="teachers-cards__scroll-x">
<div class="teachers-cards__wrapper">
<?php if ( $teachers_query->have_posts() ) : ?>
<?php while ( $teachers_query->have_posts() ) :
$teachers_query->the_post();
$t_id = get_the_ID();
$t_name = get_the_title();
$t_subj = get_post_meta( $t_id, '_teacher_direction', true );
$t_about = get_post_meta( $t_id, '_teacher_description', true );
$t_badge = get_post_meta( $t_id, '_teacher_badge', true );
$t_photo = get_post_meta( $t_id, '_teacher_avatar', true );
$start_year = get_post_meta( $t_id, '_teacher_start_year', true );
// Experience calculation.
$t_exp = '';
if ( $start_year && is_numeric( $start_year ) ) {
$e = (int) date( 'Y' ) - (int) $start_year;
if ( $e > 0 ) {
$t_exp = $e . ' лет';
}
}
// Name splitting: first part on first line, rest on second.
$name_parts = explode( ' ', $t_name, 2 );
$name_first = $name_parts[0] ?? $t_name;
$name_rest = $name_parts[1] ?? '';
// Description truncation.
$t_about_clean = $t_about ? wp_strip_all_tags( $t_about ) : '';
if ( mb_strlen( $t_about_clean ) > 200 ) {
$t_about_clean = mb_substr( $t_about_clean, 0, 200 ) . '…';
}
?>
<div class="teachers-cards__item">
<div class="teachers-cards__card">
<div class="teachers-cards__card-top">
<?php if ( $t_photo ) : ?>
<?php $photo_url = wp_get_attachment_image_url( $t_photo, array( 280, 280 ) ); ?>
<img class="teachers-cards__photo" loading="lazy" width="140" height="140"
src="<?php echo esc_url( $photo_url ?: get_template_directory_uri() . '/assets/images/no-photo.png' ); ?>"
alt="<?php echo esc_attr( $t_name ); ?>">
<?php else : ?>
<img class="teachers-cards__photo" loading="lazy" width="140" height="140"
src="<?php echo esc_url( get_template_directory_uri() . '/assets/images/no-photo.png' ); ?>"
alt="<?php echo esc_attr( $t_name ); ?>">
<?php endif; ?>
</div>
<div class="teachers-cards__card-body">
<h3 class="teachers-cards__name">
<?php echo esc_html( $name_first ); ?>
<?php if ( $name_rest ) : ?>
<br><?php echo esc_html( $name_rest ); ?>
<?php endif; ?>
</h3>
<?php if ( $t_subj ) : ?>
<p class="teachers-cards__subj"><?php echo esc_html( $t_subj ); ?></p>
<?php endif; ?>
<?php if ( $t_about_clean ) : ?>
<p class="teachers-cards__desc"><?php echo esc_html( $t_about_clean ); ?></p>
<?php endif; ?>
<div class="teachers-cards__meta">
<?php if ( $t_badge ) : ?>
<span class="teachers-cards__meta-badge"><?php echo esc_html( $t_badge ); ?></span>
<?php endif; ?>
<?php if ( $t_exp ) : ?>
<span class="teachers-cards__meta-exp"><svg aria-hidden="true" width="14" height="14" style="vertical-align:-2px;margin-right:4px"><use href="#icon-calendar"/></svg> Стаж: <?php echo esc_html( $t_exp ); ?></span>
<?php endif; ?>
</div>
<button class="teachers-cards__btn open-bitrix-form">Записаться к этому педагогу</button>
</div>
</div>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
</div>
</div>
</div>
</section>