67 lines
2.4 KiB
PHP
67 lines
2.4 KiB
PHP
<?php
|
|
/**
|
|
* Special Page Cover
|
|
*
|
|
* Renders the cover section for a special/topic page with
|
|
* background image, title, summary, and metadata.
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
$post_id = get_the_ID();
|
|
$cover_img = get_the_post_thumbnail_url($post_id, 'large');
|
|
$default_cover = isset($default_cover) ? $default_cover : '';
|
|
$show_post_count = isset($show_post_count) ? $show_post_count : true;
|
|
if (empty($cover_img) && !empty($default_cover)) {
|
|
$cover_img = $default_cover;
|
|
}
|
|
$title = get_the_title();
|
|
$excerpt = get_the_excerpt();
|
|
$summary_len = isset($summary_len) ? (int) $summary_len : 200;
|
|
|
|
if ($excerpt) {
|
|
$excerpt = wp_trim_words($excerpt, $summary_len, '...');
|
|
}
|
|
|
|
// Per-page meta
|
|
$cover_color = get_post_meta($post_id, '_aksrt_special_cover_color', true);
|
|
$cover_style = '';
|
|
if ($cover_color) {
|
|
$cover_style = 'background-color:' . sanitize_hex_color($cover_color) . ';';
|
|
}
|
|
?>
|
|
<header class="aksrt-special-cover" <?php echo $cover_style ? 'style="' . esc_attr($cover_style) . '"' : ''; ?>>
|
|
<?php if ($cover_img) : ?>
|
|
<div class="aksrt-special-cover__bg">
|
|
<img src="<?php echo esc_url($cover_img); ?>" alt=""<?php echo function_exists('aksrt_lazy_loading') ? aksrt_lazy_loading('cover') : ' loading="lazy"'; ?> class="aksrt-special-cover__img">
|
|
<div class="aksrt-special-cover__overlay"></div>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="aksrt-special-cover__content">
|
|
<h1 class="aksrt-special-cover__title"><?php echo esc_html($title); ?></h1>
|
|
|
|
<?php if ($excerpt) : ?>
|
|
<p class="aksrt-special-cover__summary"><?php echo esc_html($excerpt); ?></p>
|
|
<?php endif; ?>
|
|
|
|
<div class="aksrt-special-cover__meta">
|
|
<span class="aksrt-special-cover__date">
|
|
<i class="fas fa-calendar-alt"></i>
|
|
<?php echo esc_html(get_the_date()); ?>
|
|
</span>
|
|
<?php
|
|
if ($show_post_count) :
|
|
$children = get_pages(['child_of' => $post_id, 'parent' => $post_id, 'post_status' => 'publish', 'fields' => 'ids']);
|
|
if (!empty($children)) : ?>
|
|
<span class="aksrt-special-cover__count">
|
|
<i class="fas fa-file-alt"></i>
|
|
<?php printf(esc_html__('%d 篇文章', 'aksrt'), count($children)); ?>
|
|
</span>
|
|
<?php endif; endif; ?>
|
|
</div>
|
|
</div>
|
|
</header>
|