有两段代码用于构建 Typecho 文章归档页,效果如:http://www.jimsir.com/archives.html 代码一实现
模板代码片段一
以年份分割循环加载文章
<?php
$this->widget('Widget_Contents_Post_Recent', 'pageSize=10000')->to($archives);
$year=0; $i=0; $j=0;
while($archives->next()):
$year_tmp = date('Y',$archives->created);
$y=$year;
if ($year != $year_tmp && $year > 0) $output .= '</ul>';
if ($year != $year_tmp) {
$year = $year_tmp;
$output .= '<h2>'. $year .'</h2>';
$output .= '<ul>';
$output .= '<li><a href="'.$archives->permalink .'">'. $archives->title .'</a> <time>'.date('dM',$archives->created).'</time></li>';
}
endwhile;
$output .= '</ul>';
echo $output;
?>
模板代码片段二
以月份分割循环加载文章
<?php
$this->widget('Widget_Contents_Post_Recent', 'pageSize=10000')->to($archives);
$year=0; $mon=0; $i=0; $j=0;
while($archives->next()):
$year_tmp = date('Y',$archives->created);
$mon_tmp = date('m',$archives->created);
$y=$year; $m=$mon;
if ($mon != $mon_tmp && $mon > 0) $output .= '</ul></li>';
if ($year != $year_tmp && $year > 0) $output .= '</ul>';
if ($year != $year_tmp) {
$year = $year_tmp;
}
if ($mon != $mon_tmp) {
$mon = $mon_tmp;
$output .= '<h2>'. date('F',$archives->created) . ', ' . $year .'</h2>';
$output .= '<ul>';
}
$output .= '<li><a href="'.$archives->permalink .'">'. $archives->title .'</a> <time>'.date('dM',$archives->created).'</time></li>';
endwhile;
$output .= '</ul>';
echo $output;
?>