Files
kjweiji/page-articles.php
T
liaoxin f09f3bbfef v1.8 — 细节优化
- 首页文案更新为'自白者的栖息地'
- 近笺 12 条 + 查看全部链接
- 笺文详情页加浏览量
- 登录弹窗替代 alert
- 评论区修复双重 border-top
- 退出登录带回跳
- 时间格式统一到秒
- 文案优化
2026-05-04 13:39:20 +08:00

64 lines
2.5 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);">字里行间,尽是岁月</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">
<span class="article-title"><?php the_title(); ?></span>
<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>
<div class="article-item__meta">
<span class="article-item__date"><?php echo get_the_date('Y-m-d'); ?></span>
<span class="article-item__views">👁 <?php echo (int) kjweji_get_views(); ?></span>
</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(); ?>