排行榜 统计
  • 建站日期:2020/07/11
  • 文章总数:151 篇
  • 评论总数:377 条
  • 分类总数:5 个
  • 最后更新:1月17日

typecho创建归档页面

本文阅读 1 分钟
首页 typecho 正文

本文最后更新于2022年12月23日, 已超过461天没有更新。 如果文章内容或图片资源失效,请留言反馈,我会及时处理,谢谢!

创建模版
复制一份使用的模版中的page.php,文件名改成你自定义模版的名字。
修改模板
将复制出的page.php文件内第一行

<?php $this->need('header.php'); ?>

替换成

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

修改内容
将复制出的page.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;
?>

使用模板
然后把修改好的文件放入使用中的模板文件夹中,

在后台创建页面---自定义模板---选择归档页---发布页面即可

本文来自投稿,不代表本站立场,如若转载,请注明出处:
-- 展开阅读全文 --
通过prism.js实现Typecho代码语法高亮
« 上一篇 07-14
人生六个字
下一篇 » 07-16