farallon/page-archives.php

63 lines
2.6 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); ?>
2024-06-04 16:21:16 +08:00
<h2 class="post--single__subtitle">共包含 <?php $quantity->publishedPostsNum(); ?> 篇文章</h2>
2024-05-18 16:33:53 +08:00
<?php if ($this->options->showallwords): ?>
2024-06-05 15:59:42 +08:00
<h3><?php echo allwords(); ?></h3>
<?php endif; ?>
2024-05-18 16:33:53 +08:00
</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-30 14:47:29 +08:00
$output = '<div class="archives">'; // Start archives container
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);
2024-05-30 14:47:29 +08:00
$mon_tmp = date('m', $archives->created);
2024-05-22 14:33:23 +08:00
// 检查是否需要新的年份标题
2024-05-22 14:21:07 +08:00
if ($year != $year_tmp) {
if ($year > 0) {
2024-05-22 14:33:23 +08:00
$output .= '</ul></div>'; // 结束上一个年份的月份列表和包裹的div
2024-05-22 14:21:07 +08:00
}
2024-05-22 14:33:23 +08:00
$year = $year_tmp;
$mon = 0; // 重置月份
2024-05-22 14:39:53 +08:00
$output .= '<div class="archive-year"><h2 class="archive--title__year">' . $year . '</h2>'; // 开始新的年份div
2024-05-30 14:47:29 +08:00
}
2024-05-22 14:33:23 +08:00
// 检查是否需要新的月份标题
2024-05-22 14:21:07 +08:00
if ($mon != $mon_tmp) {
if ($mon > 0) {
2024-05-22 14:33:23 +08:00
$output .= '</ul>'; // 结束上一个月份的列表
2024-05-22 14:21:07 +08:00
}
2024-05-22 14:33:23 +08:00
$mon = $mon_tmp;
2024-05-22 14:39:53 +08:00
$output .= '<h3 class="archive--title__month"></h3>';// '. $mon . '
2024-05-22 14:33:23 +08:00
$output .= '<ul class="archive--list">'; // 开始新的月份列表
2024-05-22 14:21:07 +08:00
}
// 输出文章项
2024-05-22 14:33:23 +08:00
$output .= '<li class="archive--item">';
$output .= '<div class="archive--title"><a href="' . $archives->permalink . '">' . $archives->title . '</a></div>';
$output .= '<div class="archive--meta">' . date('m月d日', $archives->created) . '</div></li>';
}
// 循环后,确保所有标签都已经关闭
if ($mon > 0) {
$output .= '</ul>'; // 结束最后一个月份的列表
2024-05-17 15:47:27 +08:00
}
2024-05-22 14:21:07 +08:00
if ($year > 0) {
2024-05-22 14:33:23 +08:00
$output .= '</div>'; // 结束最后一个年份的div
2024-05-17 15:47:27 +08:00
}
2024-05-22 14:33:23 +08:00
$output .= '</div>'; // End archives container
2024-05-22 14:21:07 +08:00
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'); ?>