Typecho按年输出归档

说明:新建归档页面,按年输出所有文章,并显示该年份下总文章数。
演示:归档

  <?php
    Typecho_Widget::widget('Widget_Contents_Post_Recent', 'pageSize='.
    Typecho_Widget::widget('Widget_Stat')->publishedPostsNum)->to($archives);
    $date_y=0;$date_m=0;$output = '';$huan=0;
    while($archives->next()){
      $date_t = explode(",", date('Y,m,d', $archives->created));
      if($date_y > $date_t[0]){
        $date_m  = 0;
        $article_nums[] = $article_num;
        $output .= '</ul></li></ul>';
      }
      if($date_y != $date_t[0]){
        $date_y  = $date_t[0];$article_num=0;
        $article_flag[] = $tmp_flag = 'archives_'.$huan++;
        $output .= '<h2>'.$date_y.' <span>×'. $tmp_flag .'</span></h2><ul>';
      }
      $output .= '<li><time>'.$date_t[1].'.'.$date_t[2].'</time> <a href="'.$archives->permalink.'">'.$archives->title.'</a> <sup><a href="'.$archives->permalink.'#comment">'.$archives->commentsNum.'</a></sup></li>';
      $article_num++;
    }
    $article_nums[] = $article_num;
    $output .= '</ul></li></ul>';
    echo str_replace($article_flag, $article_nums, $output);
  ?>
暂无评论
标签: