香菇用自定义模板写的(Typecho)归档页面

香菇用的Typecho博客程序(就是您看到的这个)极致简洁,以至于我想要的归档都木有,虽然可以按照时间和分类归档,但我还是想要个归档所有文章的归档哎呀好绕反正就是这个意思,方便查看文章和SEO嗯,虽说有插件可以实现,我还是想折腾折腾就自己动手Coding啦啦啦啦啦N~
整页代码如下(只在本主题测试了显示效果)

<?php 
/**
 * 全部文章归档
 *
 * @package custom
 */
if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php $this->need('header.php'); ?>

    <article class="post">
     <header class="post-head">
      <h2 class="post-title">
        <a href="<?php $this->permalink() ?>"><?php $this->title() ?></a>
      </h2>
     </header>
     <section class="post-content typo">

   <h3>分类列表</h3>
   <?php $this->widget('Widget_Metas_Category_List')
                ->parse('<li><a href="{permalink}" title="{description}">{name}</a> ({count}) --> {description}</li>'); ?>

   <?php
            $this->widget('Widget_Contents_Post_Recent', 'pageSize=10000')->to($archives);
            $year=0; $mon=0; $i=0; $j=0;
            $all = array();
            $output = '';
            while($archives->next()):
                $year_tmp = date('Y',$archives->created);
                $mon_tmp = date('n',$archives->created);

                $y=$year; $m=$mon;
                if ($year != $year_tmp) {
                    $year = $year_tmp;
                    $all[$year] = array();
                }

                if ($mon != $mon_tmp) {
                    $mon = $mon_tmp;
                    array_push($all[$year], $mon);
                    $output .= "<br><h3>$year 年 $mon 月</h3>";
                }
                $output .= '<div>['.date('m-d',$archives->created).'] <a href="'.$archives->permalink .'">'.$archives->title .'</a><!--('. $archives->commentsNum.')--></div>';
            endwhile;
            echo $output;
        ?>

     </section>
    </article>

<?php $this->need('comments.php'); ?>
<?php $this->need('footer.php'); ?>
新建一个文件复制以上代码保存为archives.php放到当前主题目录下 → 在后台新建个空白单页 → 选择模板 → 发布就OK啦~
本站归档:http://www.wanghang.ac.cn/archives/

标签: none

评论已关闭