161 lines
7.5 KiB
PHP
161 lines
7.5 KiB
PHP
<?php get_header(); ?>
|
||
|
||
<?php if (is_home() && !is_paged()) : ?>
|
||
<!-- Hero -->
|
||
<div class="hero">
|
||
<h1><?php bloginfo('name'); ?></h1>
|
||
<?php
|
||
$couplet = esc_html(get_theme_mod('kjweji_hero_couplet', '空笺待写千般意,未寄先存一寸心'));
|
||
$hl1 = esc_html(get_theme_mod('kjweji_hero_couplet_hl1', '千般意'));
|
||
$hl2 = esc_html(get_theme_mod('kjweji_hero_couplet_hl2', '一寸心'));
|
||
$couplet = str_replace($hl1, '<span>' . $hl1 . '</span>', $couplet);
|
||
$couplet = str_replace($hl2, '<span>' . $hl2 . '</span>', $couplet);
|
||
?>
|
||
<p class="couplet"><?php echo $couplet; ?></p>
|
||
<p class="intro-text">
|
||
<?php echo nl2br(esc_html(get_theme_mod('kjweji_hero_intro', "这里是自白者的栖息地。\n吐槽,落笔,沉思,接住那一缕若有的情绪。\n片语只言,皆是存在。"))); ?>
|
||
</p>
|
||
</div>
|
||
<?php endif; ?>
|
||
|
||
<?php if (have_posts()) : ?>
|
||
|
||
<?php if (!is_home() || is_paged()) : ?>
|
||
<div class="section-header">
|
||
<span class="section-title">📜
|
||
<?php
|
||
if (is_category()) { single_cat_title(); }
|
||
elseif (is_tag()) { echo '标签:'; single_tag_title(); }
|
||
elseif (is_search()) { echo '搜索:' . get_search_query(); }
|
||
elseif (is_author()) { echo '作者:' . get_the_author_meta('display_name'); }
|
||
else { echo '笺文'; }
|
||
?>
|
||
</span>
|
||
</div>
|
||
<?php endif; ?>
|
||
|
||
<?php if (is_home() && !is_paged()) : ?>
|
||
<?php
|
||
// Pinned = first post
|
||
$count = 0;
|
||
$pinned_id = 0;
|
||
$posts_arr = array();
|
||
while (have_posts()) : the_post();
|
||
if ($count === 0) $pinned_id = get_the_ID();
|
||
$posts_arr[] = array('id' => get_the_ID(), 'title' => get_the_title(), 'author_id' => get_the_author_meta('ID'), 'author_name' => get_the_author_meta('display_name'), 'date' => get_the_date('Y-m-d'), 'excerpt' => kjweji_excerpt(5, 200), 'views' => kjweji_get_views(), 'url' => get_permalink(), 'thumb' => has_post_thumbnail() ? get_the_post_thumbnail_url(null, 'medium') : '');
|
||
$count++;
|
||
endwhile;
|
||
?>
|
||
|
||
<?php if ($pinned_id > 0) : ?>
|
||
<?php $p = $posts_arr[0]; ?>
|
||
<div class="pinned-section">
|
||
<div class="pinned-label">📌 编辑推荐</div>
|
||
<a href="<?php echo esc_url($p['url']); ?>" class="pinned-card">
|
||
<div class="pinned-cover">
|
||
<?php if ($p['thumb']) : ?>
|
||
<img src="<?php echo esc_url($p['thumb']); ?>" alt="<?php echo esc_attr($p['title']); ?>">
|
||
<?php endif; ?>
|
||
</div>
|
||
<div class="pinned-info">
|
||
<h3><?php echo esc_html($p['title']); ?></h3>
|
||
<p class="pinned-excerpt"><?php echo esc_html($p['excerpt']); ?></p>
|
||
<p class="pinned-meta">
|
||
<span class="pinned-meta__author"><?php echo get_avatar($p['author_id'], 16, '', '', array('class' => 'pinned-avatar')); ?><?php echo esc_html($p['author_name']); ?></span>
|
||
<span><?php echo esc_html($p['date']); ?></span>
|
||
<span>👁 <?php echo (int) $p['views']; ?></span>
|
||
</p>
|
||
</div>
|
||
</a>
|
||
</div>
|
||
<?php endif; ?>
|
||
|
||
<div class="section-header"><span class="section-title">📜 近笺</span></div>
|
||
<div class="papers-grid">
|
||
<?php
|
||
$card_i = 0;
|
||
foreach ($posts_arr as $p) :
|
||
if ($card_i === 0) { $card_i++; continue; } // skip pinned
|
||
?>
|
||
<a href="<?php echo esc_url($p['url']); ?>" class="paper-card">
|
||
<div class="card-cover">
|
||
<?php if ($p['thumb']) : ?>
|
||
<img src="<?php echo esc_url($p['thumb']); ?>" alt="<?php echo esc_attr($p['title']); ?>">
|
||
<?php endif; ?>
|
||
</div>
|
||
<div class="card-body">
|
||
<div class="card-author">
|
||
<?php echo get_avatar($p['author_id'], 14, '', '', array('class' => 'card-avatar')); ?>
|
||
<span><?php echo esc_html($p['author_name']); ?></span>
|
||
</div>
|
||
<div class="card-title"><?php echo esc_html($p['title']); ?></div>
|
||
<div class="card-excerpt"><?php echo esc_html($p['excerpt']); ?></div>
|
||
<div class="card-meta">
|
||
<span><?php echo esc_html($p['date']); ?></span>
|
||
<span>👁 <?php echo (int) $p['views']; ?></span>
|
||
</div>
|
||
</div>
|
||
</a>
|
||
<?php $card_i++; endforeach; ?>
|
||
</div>
|
||
<div style="text-align:right;margin-top:12px;">
|
||
<a href="/articles/" style="color:var(--cinnabar);font-size:13px;text-decoration:none;">查看全部 →</a>
|
||
</div>
|
||
|
||
<?php else : ?>
|
||
<!-- 非首页:列表视图 -->
|
||
<div class="article-list">
|
||
<?php while (have_posts()) : the_post(); ?>
|
||
<a href="<?php the_permalink(); ?>" class="article-item">
|
||
<span class="article-title"><?php the_title(); ?></span>
|
||
<span class="article-meta">
|
||
<span><?php the_author_meta('display_name'); ?></span>
|
||
<span><?php echo get_the_date('Y-m-d'); ?></span>
|
||
</span>
|
||
</a>
|
||
<?php endwhile; ?>
|
||
</div>
|
||
<?php endif; ?>
|
||
|
||
<?php if (is_home() && !is_paged()) : ?>
|
||
<!-- 微言摘要 -->
|
||
<?php
|
||
$recent_tucaos = get_posts(array(
|
||
'post_type' => 'tucao', 'posts_per_page' => 3,
|
||
'orderby' => 'date', 'order' => 'DESC',
|
||
));
|
||
if ($recent_tucaos) : ?>
|
||
<div class="section-header" style="margin-top:36px;">
|
||
<span class="section-title">💬 微言</span>
|
||
</div>
|
||
<?php foreach ($recent_tucaos as $t) : ?>
|
||
<div class="tucao-item">
|
||
<div class="tucao-header">
|
||
<?php echo get_avatar($t->post_author, 16, '', '', array('class' => 'tucao-avatar')); ?>
|
||
<span class="tucao-author"><?php echo esc_html(get_the_author_meta('display_name', $t->post_author)); ?></span>
|
||
<span class="tucao-time"><?php echo get_the_time('Y-m-d H:i:s', $t); ?></span>
|
||
</div>
|
||
<div class="tucao-body"><?php echo esc_html(wp_strip_all_tags($t->post_content)); ?></div>
|
||
</div>
|
||
<?php endforeach; ?>
|
||
<div style="text-align:right;margin-top:12px;">
|
||
<a href="/tucao/" style="color:var(--cinnabar);font-size:13px;text-decoration:none;">查看全部 →</a>
|
||
</div>
|
||
<?php endif; ?>
|
||
<?php endif; ?>
|
||
|
||
<?php if (!is_home() || is_paged()) : ?>
|
||
<nav class="pagination">
|
||
<?php echo paginate_links(array('prev_text' => '‹', 'next_text' => '›')); ?>
|
||
</nav>
|
||
<?php endif; ?>
|
||
|
||
<?php else : ?>
|
||
<div class="hero">
|
||
<h1><?php bloginfo('name'); ?></h1>
|
||
<p class="intro-text">尚无文章。第一篇,即将到来。</p>
|
||
</div>
|
||
<?php endif; ?>
|
||
|
||
<?php get_footer(); ?>
|