File: /home/ayxmplky/public_html/wp-content/themes/tactic/single-tactic_news.php
<?php
/**
* Single template: TACTIC News
*
* @package tactic
*/
get_header();
if ( have_posts() ) :
while ( have_posts() ) : the_post();
$current_id = get_the_ID();
$archive_url = get_post_type_archive_link( 'tactic_news' ) ?: home_url( '/news/' );
$hero_rel = '/assets/images/news-archive-hero.png';
$hero_img = file_exists( TACTIC_DIR . $hero_rel ) ? TACTIC_URI . $hero_rel : '';
if ( ! $hero_img ) {
$hero_img = has_post_thumbnail( $current_id )
? get_the_post_thumbnail_url( $current_id, 'tactic-hero' )
: '';
}
$aside_posts = get_posts( tactic_apply_news_lang_to_query_args( [
'post_type' => 'tactic_news',
'posts_per_page' => 5,
'post_status' => 'publish',
'orderby' => 'date',
'order' => 'DESC',
] ) );
$prev_candidates = get_posts( tactic_apply_news_lang_to_query_args( [
'post_type' => 'tactic_news',
'posts_per_page' => 1,
'post_status' => 'publish',
'post__not_in' => [ $current_id ],
'date_query' => [
[
'before' => get_post_field( 'post_date', $current_id ),
'inclusive' => false,
],
],
'orderby' => 'date',
'order' => 'DESC',
] ) );
$next_candidates = get_posts( tactic_apply_news_lang_to_query_args( [
'post_type' => 'tactic_news',
'posts_per_page' => 1,
'post_status' => 'publish',
'post__not_in' => [ $current_id ],
'date_query' => [
[
'after' => get_post_field( 'post_date', $current_id ),
'inclusive' => false,
],
],
'orderby' => 'date',
'order' => 'ASC',
] ) );
$prev_post = $prev_candidates[0] ?? null;
$next_post = $next_candidates[0] ?? null;
$lead = trim( (string) get_post_field( 'post_excerpt', $current_id ) );
?>
<section class="news-archive-hero"<?php if ( $hero_img ) : ?> style="background-image:url('<?php echo esc_url( $hero_img ); ?>')"<?php endif; ?>>
<div class="news-archive-hero__overlay" aria-hidden="true"></div>
<div class="news-archive-hero__container">
<h1 class="news-archive-hero__title"><?php echo esc_html( tactic_s( 'news_hero_title' ) ); ?></h1>
<p class="news-archive-hero__subtitle"><?php echo esc_html( tactic_s( 'news_hero_subtitle' ) ); ?></p>
</div>
</section>
<main id="main-content" class="news-single" role="main">
<div class="news-single__container">
<nav class="news-single__breadcrumbs" aria-label="<?php echo esc_attr( tactic_s( 'news_single_breadcrumb_aria' ) ); ?>">
<a href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php echo esc_html( tactic_s( 'nav_home' ) ); ?></a>
<span aria-hidden="true">></span>
<a href="<?php echo esc_url( $archive_url ); ?>"><?php echo esc_html( tactic_s( 'news_breadcrumb_archive' ) ); ?></a>
<span aria-hidden="true">></span>
<span><?php echo esc_html( get_the_title() ); ?></span>
</nav>
<div class="news-single__layout">
<aside class="news-single__aside" role="complementary" aria-label="<?php echo esc_attr( tactic_s( 'news_article_list_aria' ) ); ?>">
<h2 class="news-single__aside-title"><?php echo esc_html( tactic_s( 'news_articles_title' ) ); ?></h2>
<div class="news-single__aside-list">
<?php foreach ( $aside_posts as $p ) : ?>
<a class="news-single__aside-item <?php echo (int) $p->ID === (int) $current_id ? 'is-active' : ''; ?>" href="<?php echo esc_url( get_permalink( $p->ID ) ); ?>">
<?php echo esc_html( wp_trim_words( get_the_title( $p->ID ), 8, '...' ) ); ?>
</a>
<?php endforeach; ?>
</div>
<div class="news-single__aside-nav">
<?php if ( $next_post ) : ?>
<a href="<?php echo esc_url( get_permalink( $next_post->ID ) ); ?>" aria-label="<?php echo esc_attr( tactic_s( 'news_prev_article_aria' ) ); ?>">←</a>
<?php else : ?>
<span class="is-disabled">←</span>
<?php endif; ?>
<?php if ( $prev_post ) : ?>
<a href="<?php echo esc_url( get_permalink( $prev_post->ID ) ); ?>" aria-label="<?php echo esc_attr( tactic_s( 'news_next_article_aria' ) ); ?>">→</a>
<?php else : ?>
<span class="is-disabled">→</span>
<?php endif; ?>
</div>
</aside>
<article <?php post_class( 'news-single__article' ); ?>>
<header class="news-single__header">
<h1 class="news-single__title"><?php the_title(); ?></h1>
<?php if ( $lead ) : ?>
<p class="news-single__lead"><?php echo esc_html( $lead ); ?></p>
<?php endif; ?>
</header>
<?php if ( has_post_thumbnail() ) : ?>
<div class="news-single__thumb">
<?php the_post_thumbnail( 'tactic-news-thumb', [ 'loading' => 'lazy' ] ); ?>
</div>
<?php endif; ?>
<div class="entry-content news-single__content">
<?php the_content(); ?>
</div>
<div class="news-single__date-wrap">
<time class="news-single__date" datetime="<?php echo esc_attr( get_the_date( 'Y-m-d' ) ); ?>">
<?php echo esc_html( get_the_date( 'd.m.Y' ) ); ?>
</time>
</div>
</article>
</div>
</div>
</main>
<?php
endwhile;
endif;
get_footer();