Files
kjweiji/page-articles.php
T

69 lines
2.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* Template Name: 笺文列表
*/
get_header();
$pg = isset($_GET['pg']) ? max(1, (int) $_GET['pg']) : 1;
$per_page = 20;
$query = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => $per_page,
'offset' => ($pg - 1) * $per_page,
));
$total = wp_count_posts('post')->publish;
$total_pages = ceil($total / $per_page);
?>
<div class="section-header">
<span class="section-title">📜 笺文</span>
<span class="section-filter" style="font-size:13px;color:var(--ink-lighter);"><?php echo esc_html(get_theme_mod('kjweji_articles_subtitle', '字里行间,尽是岁月')); ?></span>
</div>
<?php if ($query->have_posts()) : ?>
<div class="article-list">
<?php while ($query->have_posts()) : $query->the_post(); ?>
<a href="<?php the_permalink(); ?>" class="article-item">
<?php if (has_post_thumbnail()) : ?>
<div class="article-item__thumb">
<?php the_post_thumbnail('thumbnail', array('alt' => get_the_title())); ?>
</div>
<?php endif; ?>
<div class="article-item__main">
<div class="article-item__title-row">
<span class="article-title"><?php the_title(); ?></span>
<span class="article-item__date"><?php echo get_the_date('Y-m-d'); ?></span>
</div>
<div class="article-item__sub-row">
<span class="article-item__author"><?php echo get_avatar(get_the_author_meta('ID'), 14, '', '', array('class' => 'article-avatar')); ?> <?php the_author_meta('display_name'); ?></span>
<div class="article-item__stats">
<span class="article-item__comments">💬 <?php echo (int) get_comments_number(); ?></span>
<span class="article-item__views">👁 <?php echo (int) kjweji_get_views(); ?></span>
</div>
</div>
</div>
</a>
<?php endwhile; ?>
</div>
<?php if ($total_pages > 1) : ?>
<nav class="pagination">
<?php
$base = home_url('/articles/');
if ($pg > 1) echo '<a class="page-numbers prev" href="' . $base . '?pg=' . ($pg - 1) . '"></a>';
for ($i = 1; $i <= $total_pages; $i++) {
$cls = $i == $pg ? 'page-numbers current' : 'page-numbers';
echo '<a class="' . $cls . '" href="' . $base . '?pg=' . $i . '">' . $i . '</a>';
}
if ($pg < $total_pages) echo '<a class="page-numbers next" href="' . $base . '?pg=' . ($pg + 1) . '"></a>';
?>
</nav>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p style="color:var(--ink-lighter);text-align:center;padding:60px 0;">暂无文章</p>
<?php endif; ?>
<?php get_footer(); ?>