在站点的主题目录下,新建一个任意名称的php文件,我的命名为 archives.php ,文件内容为:


  <?php 
/**
 * 文章归档
 * 
 * @package custom 
 * 
 */$this->need('header.php');
?>

<!--page.php-->

  <div>
  
  <h4 class="title"><strong>&nbsp;&nbsp;文章归档</strong></h4>
<?php $this->widget('Widget_Contents_Post_Recent', 'pageSize=10000')->to($archives);
    $year=0; $mon=0; $i=0; $j=0;
    $output = '<article class="archives"><ul class="archives-list">';
    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></div></li></article>';  //结束拼接
        if ($year != $year_tmp && $year > 0) $output .= '</ul>';
        if ($year != $year_tmp) {
            $year = $year_tmp;
            //$output .= '<h4>'. $year .' 年</h4><ul>'; 
        }
        if ($mon != $mon_tmp) {
            $mon = $mon_tmp;
            $output .= '<article class="archives"><div class="item"><ul><h4>'.$year .'-'. $mon .'</h4>'; 
        }
        $output .= '<li><time>'.date('',$archives->created).'</time><a href="'.$archives->permalink .'">'. $archives->title .'</a></li>'; //输出文章日期和标题
    endwhile;
    
    echo $output;
?>

</div>

完成后,打开博客的后台,创建一个名为 归档 的页面,内容为空,自定义模板中选择为归档页面就OK了。


本文链接:给博客增加归档页面 - https://soft.cry33.com/archives/6.html

版权声明:原创文章 遵循 CC 4.0 BY-SA 版权协议,转载请附上原文链接和本声明。

分类:默认分类

标签:none

添加新评论