diff options
| author | BigCoke233 <hi@guhub.cn> | 2020-05-30 15:17:22 +0800 |
|---|---|---|
| committer | BigCoke233 <hi@guhub.cn> | 2020-05-30 15:17:22 +0800 |
| commit | c3bb692fe6a7289cac4b726e9887d4c2304110ff (patch) | |
| tree | 7cb221cf73ae3c90145f15600c8b28ded00b3a33 /pagefile.php | |
| parent | bd0a23b052dc750db72d2b98349044a56ede2419 (diff) | |
:zap: Perf: 归档页面,折叠往年的文章列表
Diffstat (limited to 'pagefile.php')
| -rw-r--r-- | pagefile.php | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/pagefile.php b/pagefile.php index 7a9065f..4d03cac 100644 --- a/pagefile.php +++ b/pagefile.php @@ -25,24 +25,23 @@ $this->need('includes/header.php'); <br />
<h2>文章归档</h2>
<ul class="archives-list">
- <?php
- $this->widget('Widget_Contents_Post_Recent', 'pageSize=10000')->to($archives);
- $year=0; $mon=0; $i=0; $j=0;
- $output = '<div id="archives">';
- while($archives->next()):
- $year_tmp = date('Y',$archives->created);
- $mon_tmp = date('m',$archives->created);
- $y=$year; $m=$mon;
- if ($year != $year_tmp) {
- $year = $year_tmp;
- $output .= '<h3 class="archives-year">'. $year .' 年</h3>'; //输出年份
- }
- $mon = $mon_tmp;
- $output .= '<li><a href="'.$archives->permalink .'" class="no-line"><span class="archives-date">'. $mon .'-'.date('d ',$archives->created).'</span> '. $archives->title .'</a></li>'; //输出文章日期和标题
- endwhile;
- $output .= '</li></div>';
- echo $output;
- ?>
+ <?php
+ $archives = Contents::archives($this);
+ $number = 0;
+ foreach($archives as $year => $posts) {
+ $detailsOpen = ($number === 0) ? ' open' : NULL;
+ echo '<details'.$detailsOpen.'>';
+ echo '<summary>'.$year.' 年<small class="archives-count">共 '.count($posts).' 篇文章</small></summary>';
+ foreach($posts as $created => $post) {
+ echo '<li><a href="'.$post['permalink'].'" class="no-line">
+ <span class="archives-date">'.date('m-d', $created).'</span>
+ '.$post['title'].'
+ </a></li>';
+ }
+ echo '</details>';
+ $number++;
+ }
+ ?>
</ul>
</div>
</div>
|
