183 lines
7.4 KiB
PHP
183 lines
7.4 KiB
PHP
<?php
|
||
/**
|
||
* Hero-секция главной страницы
|
||
* .section-bg .ds-hero
|
||
*
|
||
* @package Dekart
|
||
* @since 1.0.0
|
||
*/
|
||
|
||
if ( ! defined( 'ABSPATH' ) ) {
|
||
exit;
|
||
}
|
||
|
||
// ─── ВСПОМОГАТЕЛЬНАЯ ФУНКЦИЯ — Carbon Fields с проверкой ───
|
||
if ( ! function_exists( 'crb_get_theme_option' ) ) {
|
||
function crb_get_theme_option( string $key, $default = '' ) {
|
||
return function_exists( 'carbon_get_theme_option' )
|
||
? carbon_get_theme_option( $key ) ?: $default
|
||
: $default;
|
||
}
|
||
}
|
||
|
||
if ( ! function_exists( 'crb_get_post_meta' ) ) {
|
||
function crb_get_post_meta( int $post_id, string $key, $default = '' ) {
|
||
return function_exists( 'carbon_get_post_meta' )
|
||
? carbon_get_post_meta( $post_id, $key ) ?: $default
|
||
: $default;
|
||
}
|
||
}
|
||
|
||
// ─── ДАННЫЕ ФИЛИАЛА ───
|
||
$branch_phone = get_option( 'branch_phone' ) ?: crb_get_theme_option( 'site_phone' );
|
||
$branch_city = get_option( 'branch_city' ) ?: crb_get_theme_option( 'site_city', 'Щёлково' );
|
||
$branch_city_prep = get_option( 'branch_city_prep', 'в Щёлково' );
|
||
$branch_addr = get_option( 'branch_address' ) ?: crb_get_theme_option( 'site_address' );
|
||
|
||
// ─── УЧЕБНЫЙ ГОД ───
|
||
$current_year = (int) current_time( 'Y' );
|
||
$next_year = $current_year + 1;
|
||
$school_year = $current_year . '/' . $next_year;
|
||
|
||
// ─── ДАННЫЕ СТРАНИЦЫ ───
|
||
$post_id = (int) get_the_ID();
|
||
$foto_id = crb_get_post_meta( $post_id, 'banner_img_desktop' );
|
||
$banner_src = '';
|
||
$banner_alt = 'Частная школа Декарт в Щёлково';
|
||
|
||
if ( $foto_id ) {
|
||
$foto_id = absint( $foto_id );
|
||
$banner_src = wp_get_attachment_url( $foto_id );
|
||
$_alt = get_post_meta( $foto_id, '_wp_attachment_image_alt', true );
|
||
if ( $_alt ) {
|
||
$banner_alt = $_alt;
|
||
}
|
||
}
|
||
|
||
// ─── СТАТИСТИКА ───
|
||
$hero_stats = crb_get_post_meta( $post_id, 'hero_stats' );
|
||
if ( empty( $hero_stats ) || ! is_array( $hero_stats ) ) {
|
||
$hero_stats = [
|
||
[ 'stat_number' => '12+', 'stat_label' => 'лет опыта' ],
|
||
[ 'stat_number' => '500+', 'stat_label' => 'выпускников' ],
|
||
[ 'stat_number' => 'до 12', 'stat_label' => 'человек в классе' ],
|
||
];
|
||
}
|
||
|
||
// ─── ЗВЁЗДЫ (SVG один раз) ───
|
||
$star_svg = '<svg width="18" height="18" viewBox="0 0 20 20" fill="none"><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" fill="currentColor"/></svg>';
|
||
|
||
// ─── ПЛАШКИ (float-блоки) ───
|
||
$floats = [
|
||
[ 'icon' => 'teacher', 'text' => 'Педагоги с опытом от 10 лет' ],
|
||
[ 'icon' => 'users', 'text' => 'Классы до 12 человек' ],
|
||
[ 'icon' => 'clock', 'text' => 'Первая смена + продлёнка' ],
|
||
];
|
||
|
||
// ─── ФОРМАТИРОВАНИЕ ТЕЛЕФОНА ───
|
||
$phone_clean = $branch_phone ? preg_replace( '/[\s\-\–\(\)]/', '', $branch_phone ) : '';
|
||
?><section class="section-bg ds-hero" data-bg="hero" id="hero-front" aria-labelledby="hero-front-title">
|
||
<div class="ds-container">
|
||
<div class="ds-hero__inner">
|
||
|
||
<div class="ds-hero__content">
|
||
|
||
<?php if ( $branch_addr || $branch_city ) : ?>
|
||
<div class="ds-hero__address">
|
||
<svg aria-hidden="true" width="16" height="16"><use href="#icon-location-pin"/></svg>
|
||
<span><?php echo esc_html( trim( $branch_addr . ( $branch_addr && $branch_city ? ' — ' : '' ) . $branch_city ) ); ?></span>
|
||
</div>
|
||
<?php endif; ?>
|
||
|
||
<h1 id="hero-front-title" class="ds-hero__h1"><?php echo esc_html( crb_get_post_meta( $post_id, 'banner_h1', 'Частная школа ' . esc_html( $branch_city_prep ) ) ); ?></h1>
|
||
|
||
<p class="ds-hero__subtitle">Небольшие классы до 12 человек, опытные педагоги и английский с 1 класса. Первая смена + продлёнка до 18:00. Приходите посмотреть школу и познакомиться с учителем. Открыт набор на <span class="ds-hero__year"><?php echo esc_html( $school_year ); ?></span> год.</p>
|
||
|
||
<?php if ( $hero_stats ) : ?>
|
||
<div class="ds-hero__metrics">
|
||
<?php foreach ( $hero_stats as $stat ) :
|
||
$num = $stat['stat_number'] ?? '';
|
||
$lbl = $stat['stat_label'] ?? '';
|
||
if ( '' === $num ) { continue; }
|
||
?>
|
||
<div class="ds-hero__metric reveal">
|
||
<span class="ds-hero__metric-number"><?php echo esc_html( $num ); ?></span>
|
||
<span class="ds-hero__metric-label"><?php echo esc_html( $lbl ); ?></span>
|
||
</div>
|
||
<?php endforeach; ?>
|
||
</div>
|
||
<?php endif; ?>
|
||
|
||
<div class="ds-hero__rating-badge">
|
||
<span class="ds-hero__rating-stars" aria-hidden="true">
|
||
<?php for ( $i = 1; $i <= 5; $i++ ) : ?>
|
||
<span class="ds-star ds-star--<?php echo $i; ?>"><?php echo $star_svg; ?></span>
|
||
<?php endfor; ?>
|
||
</span>
|
||
<span class="ds-hero__rating-text">4.9 из 5 на основе 190 отзывов на внешних площадках</span>
|
||
</div>
|
||
|
||
<button class="ds-hero__cta-btn btn-write" data-track="hero_cta">Получить консультацию</button>
|
||
|
||
<div class="ds-hero__assurance">
|
||
<span class="ds-hero__assurance-item">Можно просто прийти и посмотреть</span>
|
||
<span class="ds-hero__assurance-item">Бесплатное тестирование ребёнка</span>
|
||
</div>
|
||
|
||
<?php if ( $branch_phone && $phone_clean ) : ?>
|
||
<p class="ds-hero__phone">Или позвоните: <a href="tel:<?php echo esc_attr( $phone_clean ); ?>" aria-label="Позвонить в школу Декарт: <?php echo esc_attr( $branch_phone ); ?>"><?php echo esc_html( $branch_phone ); ?></a></p>
|
||
<?php endif; ?>
|
||
|
||
</div>
|
||
|
||
<div class="ds-hero__visual">
|
||
<div class="ds-hero__visual-glow" aria-hidden="true"></div>
|
||
|
||
<div class="ds-hero__photo-wrap">
|
||
<div class="ds-hero__photo-frame">
|
||
<img class="ds-hero__photo"
|
||
src="<?php echo esc_url( $banner_src ?: get_template_directory_uri() . '/assets/images/logo-svg.svg' ); ?>"
|
||
alt="<?php echo esc_attr( $banner_alt ); ?>"
|
||
loading="eager" decoding="async"
|
||
width="600" height="600">
|
||
</div>
|
||
<div class="ds-hero__photo-ring" aria-hidden="true"></div>
|
||
</div>
|
||
|
||
<?php foreach ( $floats as $idx => $float ) : ?>
|
||
<div class="ds-hero__float ds-hero__float--<?php echo esc_attr( $idx + 1 ); ?>">
|
||
<span class="ds-hero__float-icon"><svg aria-hidden="true" width="24" height="24"><use href="#icon-<?php echo esc_attr( $float['icon'] ); ?>"/></svg></span>
|
||
<span><?php echo esc_html( $float['text'] ); ?></span>
|
||
</div>
|
||
<?php endforeach; ?>
|
||
|
||
</div>
|
||
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
<?php
|
||
// CRO-трекинг — добавляем через wp_add_inline_script к front-page.js
|
||
add_action( 'wp_footer', function () {
|
||
if ( wp_script_is( 'front-page-script', 'enqueued' ) ) {
|
||
wp_add_inline_script( 'front-page-script', '
|
||
document.addEventListener("DOMContentLoaded", function() {
|
||
document.querySelectorAll("[data-track]").forEach(function(el) {
|
||
el.addEventListener("click", function() {
|
||
if (typeof gtag === "function") {
|
||
gtag("event", "hero_click", {
|
||
"event_category": "engagement",
|
||
"event_label": this.dataset.track
|
||
});
|
||
}
|
||
if (typeof ym === "function") {
|
||
ym(' . ( defined( 'YM_COUNTER_ID' ) ? esc_js( YM_COUNTER_ID ) : 'null' ) . ', "reachGoal", this.dataset.track);
|
||
}
|
||
});
|
||
});
|
||
});
|
||
' );
|
||
}
|
||
}, 100 );
|