创建自定义模版页面文件

复制一份你模版的page.php页面,文件名改成你归档页面自定义模版名字(举例all.php)

添加自定义模版标识

将归档页面模版(all.php)内第一行<?php $this->need('header.php'); ?>替换成

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

替换主体内容为输出归档文章列表

将all.php文件内
<?php $this->content(); ?>
替换成

<?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 ($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>'. $mon .' 月</span><ul>'; //输出月份
        }
        $output .= '<li>'.date('d日: ',$archives->created).'<a href="'.$archives->permalink .'">'. $archives->title .'</a> <em>('. $archives->commentsNum.')</em></li>'; //输出文章日期和标题
    endwhile;
    $output .= '</ul></li></ul></div>';
    echo $output;
?>

每个不同的typecho page.php文章主体内容代码我不知道是不是一样的,可以分析下代码就知道了。这样做是为了保证独立页面的归档页和模版风格保持一致。

标签: typecho, typecho 归档

已有 9 条评论

  1. 不错,直接使用。

  2. un un

    这个要上传到哪里

  3. 已用上,非常感谢! ::aru:flower::

  4. 大鸟 大鸟

    我的pjax怎么要刷新才能评论

  5. 抱走٩(ˊᗜˋ*)و

  6. 磁悬浮代码· 磁悬浮代码·

    53621

  7. 改了一下样式,已经用上,太感谢了

  8. 有用!

  9. 不错,我喜欢,收藏了、、、

添加新评论