Files
kjweiji/page-articles.php
T
liaoxin e123fbe9e8 v1.0 — 功能完整版本
- 首页: Hero + 编辑推荐 + 近笺卡片 + 微言摘要
- 笺文: 列表 + 分页(头像+作者+日期+浏览量)
- 微言: 列表 + 评论折叠
- 拾影: 瀑布流 + 灯箱
- 文章详情: 封面 + 正文 + 评论
- 图片: 缩略图 soft crop,原图裁黑边
- 头像: 本地 SVG 替换 Gravatar
- 导航: 激活状态圆点指示
- 安装: 自动创建页面和菜单
2026-05-03 22:06:59 +08:00

58 lines
2.1 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 = 3;
$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>
</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">
<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(); ?>