/ 生活记录 / 10浏览

整了一个typecho归档页面

原主题的归档页面不是我的菜,而网上的归档插件,在我的博客了发神经,时好时坏,无奈之下,只好自己参照各种版本的教程,还有官网的wiki,整出一个这样的归档页面来,没有加载js,全部就是几行代码而已,喜欢的同学直接拿去,不谢!

20161111105057.png

<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php   
/**  
    * archives  
    *  
    * @package custom  
    */  
$this->need('header.php'); ?>   
    <div id="mainbox2">   
            <div class="post"  id="post-<?php $this->cid(); ?>">   
            <h1><span class="post-title"><a href="<?php $this->permalink() ?>" title=""><?php  $this->title() ?></a></span></h1>   
            <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'); ?>

另外把css美化一下,各位参照自己的主题动手修改,我的css如下:

div#mainbox2 {
    position: relative;
    margin: 9% auto 5%;
    padding: 1% 3% 2%;
    max-width: 800px;
    width: 100%;
    background-color: #fff;
    -webkit-box-shadow: 1px 2px 3px #ddd;
    box-shadow: 1px 2px 3px #ddd;
    -webkit-border-radius: 3px;
    border-radius: 3px;
}
更新于
guest
36 评论
Inline Feedbacks
View all comments
fooleap
8 年 之前

链接颜色有些深,感觉不大协调,或许可以考虑换一种颜色。

摩天之星
8 年 之前

哈哈,谢谢了

灰狼
8 年 之前

归档插件一直都可以用的。只是JQ要在顶部(插件需要JQ支持)

synyan
8 年 之前

建议还要考虑一个情况,比如有些博客文章太多,会导致崩溃,需要设置一个翻页。

synyan
8 年 之前
Reply to  Mr.He

参考wp内置的nextpage函数

Lopwon
8 年 之前

不错,有按月归档的功能

Lopwon
8 年 之前
Reply to  Mr.He

官方论坛也有人提过需求,貌似没有修改方法

Kay
Kay
8 年 之前

其实不需要翻页也可以的

小彦
8 年 之前

可以直接粘贴用,不是插件,多了个选择~

工控人生
8 年 之前

会折腾的技术男……

姜辰
8 年 之前

看样子我还是静静的躲在EM吧····

山野愚人居
8 年 之前

无聊,没事你的这套皮想往wordpress上移植,枝干已基本成型,哈哈,不过评论ajax卡壳了……
test.byspace.net

Weidan
Weidan
8 年 之前

技术大牛赞!

Weidan
Weidan
8 年 之前
Reply to  Mr.He

最近有事就没怎么更,我也是看心情更的

Roogle
8 年 之前

源码已经拿走了,不过样式并不太理想,还要改动

陆半农
8 年 之前

已经用上,谢谢!文章不多,没有分页也没关系,以后如果要分页,再说吧。

沐可
7 年 之前

感谢分享!

夏目贵志
6 年 之前

不错 !!

meo
meo
5 年 之前

请问,这个如何使用?菜鸟一枚,可否详细步骤?谢谢

嗷嗷
5 年 之前

这个归档页面很得我心,马上试试看~

老何
4 月 之前

邮件回复没有了啊