Typecho 建立文章归档页面

发布时间:2021-03-30

在主题目录下创建archives.php页面

添加以下代码即可:

<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php   
/**  
* archives  
*  
* @Author GOJOGO 
*/  
$this->need('header.php'); ?>   
<div id="mainbox2">   
<div class="post"  id="post-<?php $this->cid(); ?>">   
<h3><span class="post-title"><a href="<?php $this->permalink() ?>" title=""><?php  $this->title() ?></a></span></h3>   
<div class="clear"></div>   
<div class="entry">   
<?php $this->widget('Widget_Contents_Post_Recent', 'pageSize=10000')->to($archives);
$year=0; $mon=0; $i=0; $j=0;
$output = '<div class="post-content cf">';
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;
        $output .= '<h3>'. $year .' 年</h3><ul>'; 
    }
    if ($mon != $mon_tmp) {
        $mon = $mon_tmp;
        $output .= '<li><span>'. $year .' 年'. $mon .' 月</span><ul>';
    }
    $output .= '<li>'.date('d日: ',$archives->created).'<a href="'.$archives->permalink .'">'. 
$archives->title .'</a> ('. $archives->commentsNum.')</li>';
endwhile;
$output .= '</ul></li></ul></div>';
echo $output;
?>          <div class="clear"></div>   
        </div>   
    </div>   
 </div>
<?php $this->need('footer.php'); ?>

打赏


哇 你要支持我吗?太慷慨了!谢谢
上一篇
下一篇