File: /home/ayxmplky/public_html/wp-content/themes/tactic/template-parts/home/hero.php
<?php
/**
* Template Part: Hero (главный баннер)
*
* @package tactic
*/
$front_id = (int) get_option( 'page_on_front' );
$bg_id = $front_id ? (int) get_post_meta( $front_id, '_hero_bg_id', true ) : 0;
$bg_url = $bg_id ? wp_get_attachment_image_url( $bg_id, 'tactic-hero' ) : '';
$slide_ids_raw = (string) get_option( 'tactic_hero_slider_ids', '' );
if ( $slide_ids_raw === '' && $front_id ) {
$slide_ids_raw = (string) get_post_meta( $front_id, '_hero_slide_ids', true );
}
$slide_ids = array_filter( array_map( 'absint', explode( ',', $slide_ids_raw ) ) );
$slides = [];
foreach ( $slide_ids as $slide_id ) {
$slide_url = wp_get_attachment_image_url( $slide_id, 'tactic-hero' );
if ( $slide_url ) {
$slides[] = $slide_url;
}
}
if ( empty( $slides ) && $bg_url ) {
$slides[] = $bg_url;
}
$title = $front_id ? get_post_meta( $front_id, '_hero_title', true ) : '';
$subtitle = $front_id ? get_post_meta( $front_id, '_hero_subtitle', true ) : '';
$btn1_text = $front_id ? get_post_meta( $front_id, '_hero_btn1_text', true ) : '';
$btn1_url = $front_id ? get_post_meta( $front_id, '_hero_btn1_url', true ) : '';
$btn2_text = $front_id ? get_post_meta( $front_id, '_hero_btn2_text', true ) : '';
$btn2_url = $front_id ? get_post_meta( $front_id, '_hero_btn2_url', true ) : '';
// Значения по умолчанию
$title = $title ?: tactic_s( 'hero_title' );
$subtitle = $subtitle ?: tactic_s( 'hero_subtitle' );
$btn1_text = $btn1_text ?: tactic_s( 'hero_btn1' );
$btn2_text = $btn2_text ?: tactic_s( 'hero_btn2' );
// Для EN всегда используем локализованные строки,
// чтобы старые ZH-метаполя не перебивали перевод.
if ( tactic_current_lang() === 'en' ) {
$title = tactic_s( 'hero_title' );
$subtitle = tactic_s( 'hero_subtitle' );
$btn1_text = tactic_s( 'hero_btn1' );
$btn2_text = tactic_s( 'hero_btn2' );
}
?>
<section
class="hero<?php echo ! empty( $slides ) ? ' hero--has-bg' : ''; ?>"
<?php if ( empty( $slides ) && $bg_url ) : ?>
style="background-image: url('<?php echo esc_url( $bg_url ); ?>')"
<?php endif; ?>
aria-label="<?php echo esc_attr( tactic_s( 'hero_aria' ) ); ?>"
>
<?php if ( ! empty( $slides ) ) : ?>
<div class="hero__slides" id="hero-slides" data-autoplay="1" data-interval="5000">
<?php foreach ( $slides as $i => $slide_url ) : ?>
<div class="hero__slide<?php echo $i === 0 ? ' is-active' : ''; ?>" style="background-image:url('<?php echo esc_url( $slide_url ); ?>')" aria-hidden="<?php echo $i === 0 ? 'false' : 'true'; ?>"></div>
<?php endforeach; ?>
</div>
<?php if ( count( $slides ) > 1 ) : ?>
<div class="hero__dots" id="hero-dots" aria-label="<?php echo esc_attr( tactic_s( 'hero_pagination_aria' ) ); ?>"></div>
<?php endif; ?>
<?php endif; ?>
<div class="hero__overlay" aria-hidden="true"></div>
<div class="hero__content">
<div class="hero__text">
<h1 class="hero__title"><?php echo esc_html( $title ); ?></h1>
<p class="hero__subtitle"><?php echo esc_html( $subtitle ); ?></p>
</div>
<div class="hero__buttons">
<?php if ( $btn1_url ) : ?>
<a href="<?php echo esc_url( $btn1_url ); ?>" class="btn btn--primary">
<?php echo esc_html( $btn1_text ); ?>
</a>
<?php else : ?>
<span class="btn btn--primary"><?php echo esc_html( $btn1_text ); ?></span>
<?php endif; ?>
<?php if ( $btn2_url ) : ?>
<a href="<?php echo esc_url( $btn2_url ); ?>" class="btn btn--outline">
<?php echo esc_html( $btn2_text ); ?> <span aria-hidden="true">→</span>
</a>
<?php else : ?>
<span class="btn btn--outline"><?php echo esc_html( $btn2_text ); ?> <span aria-hidden="true">→</span></span>
<?php endif; ?>
</div>
</div>
</section>