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 | |
| parent | bd0a23b052dc750db72d2b98349044a56ede2419 (diff) | |
:zap: Perf: 归档页面,折叠往年的文章列表
| -rw-r--r-- | assets/css/main/page.css | 8 | ||||
| -rw-r--r-- | libs/Contents.php | 25 | ||||
| -rw-r--r-- | pagefile.php | 35 |
3 files changed, 47 insertions, 21 deletions
diff --git a/assets/css/main/page.css b/assets/css/main/page.css index 0288c73..6831b92 100644 --- a/assets/css/main/page.css +++ b/assets/css/main/page.css @@ -74,10 +74,14 @@ .archives-list a:hover {
background: #e6e6e6
}
-.archives-date {
- color: gray;
+.archives-date,
+.archives-count {
+ color: gray!important;
letter-spacing: 0;
}
+.archives-count {
+ margin-left: 5px
+}
/* Links */
.links-box {
margin: 10px;
diff --git a/libs/Contents.php b/libs/Contents.php index 055d4ce..b424add 100644 --- a/libs/Contents.php +++ b/libs/Contents.php @@ -314,4 +314,27 @@ class Contents ), '', ' - '); Helper::options()->title(); } -} + + /** + * 内容归档 + */ + public static function archives($widget) { + $db = Typecho_Db::get(); + $rows = $db->fetchAll($db->select() + ->from('table.contents') + ->order('table.contents.created', Typecho_Db::SORT_DESC) + ->where('table.contents.type = ?', 'post') + ->where('table.contents.status = ?', 'publish')); + + $stat = array(); + foreach ($rows as $row) { + $row = $widget->filter($row); + $arr = array( + 'title' => $row['title'], + 'permalink' => $row['permalink']); + + $stat[date('Y', $row['created'])][$row['created']] = $arr; + } + return $stat; + } +}
\ No newline at end of file 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>
|
