Files
kjweiji/page-articles.php
T
liaoxin 16c3e10494 v1.1 — 图片/头像/作者/日期全面优化
- 图片: 缩略图改为 soft crop,原图裁黑边
- 头像: 团队证件照替换 SVG,CSS 约束尺寸和圆角
- 作者: 了心/墨羽/探子三个真实用户
- 笺文列表: 左侧增加封面缩略图
- 分页: 20篇/页
- 详情页: 返回笺文链接 + 头像尺寸约束
- 作者页: 高清头像 + 中文日期
- 微言: 作者随机 + 时间匹配内容
2026-05-03 23:59:38 +08:00

63 lines
2.3 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>
</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(); ?>