farallon/page-archives.php

63 lines
2.5 KiB
PHP
Raw Normal View History

2024-05-17 15:47:27 +08:00
<?php
/**
* 文章归档
*
* @package custom
*/
if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php $this->need('header.php'); ?>
2024-05-18 15:06:04 +08:00
<section class="site--main">
2024-05-18 09:24:49 +08:00
<header class="archive--header">
2024-05-17 15:47:27 +08:00
<h1 class="post--single__title"><?php $this->title() ?></h1>
<?php Typecho_Widget::widget('Widget_Stat')->to($quantity); ?>
<h2 class="archive--title__year">共包含 <?php $quantity->publishedPostsNum(); ?> 篇文章</h2>
2024-05-18 16:33:53 +08:00
<?php if ($this->options->showallwords): ?>
<h3><?php echo allwords(); ?></h3>
<?php endif; ?>
</header>
2024-05-22 14:21:07 +08:00
<div class="page--archive">
<?php
$stat = Typecho_Widget::widget('Widget_Stat');
Typecho_Widget::widget('Widget_Contents_Post_Recent', 'pageSize=' . $stat->publishedPostsNum)->to($archives);
$year = 0; $mon = 0;
2024-05-18 09:24:49 +08:00
$output = '<div class="archives">';
2024-05-22 14:21:07 +08:00
while ($archives->next()) {
2024-05-17 15:47:27 +08:00
$year_tmp = date('Y', $archives->created);
$mon_tmp = date('m', $archives->created);
2024-05-22 14:21:07 +08:00
// 检查年份和月份是否变化
if ($year != $year_tmp) {
if ($year > 0) {
$output .= '</ul></div>'; // 结束上一个年份的ul和div
}
$year = $year_tmp; $mon = 0; // 更新年份和重置月份
$output .= '<h2 class="archive--title__year">' . date('Y', $archives->created) . '</h2>'; // 输出新的年份
}
if ($mon != $mon_tmp) {
if ($mon > 0) {
$output .= '</ul>'; // 结束上一个月份的ul
}
$mon = $mon_tmp; // 更新月份
$output .= '<h3 class="archive--title__month">'. date('M', $archives->created) . '</h3><ul class="archive--list" aria-label="' . date('Y年m月', $archives->created) . '">'; // 输出新的月份和开始新的列表
}
// 输出文章项
$output .= '<li class="archive--item"><div class="archive--title"><a href="' . $archives->permalink . '">' . $archives->title . '</a></div>';
$output .= '<div class="archive--meta">' . date('m月d日', $archives->created) . '</div></li>';
2024-05-17 15:47:27 +08:00
}
2024-05-22 14:21:07 +08:00
if ($year > 0) {
$output .= '</ul></div>'; // 确保结束最后一个月份列表和div
2024-05-17 15:47:27 +08:00
}
2024-05-22 14:21:07 +08:00
$output .= '</div>'; // 结束归档div
echo $output;
?>
</div>
2024-05-18 15:06:04 +08:00
</section>
2024-05-17 15:47:27 +08:00
<?php $this->need('footer.php'); ?>