php - typecho怎么做日期归档文章循环?
PHPz
PHPz 2017-04-11 09:43:19
[PHP讨论组]
<?php $this->widget('Widget_Contents_Post_Date')->to($timeline);?>
    <?php if ($timeline->have()): ?>
        <?php while($timeline->next()): ?>
        <?php $timelist = $this->widget('Widget_Archive@timeline_'.$timeline->date, '&pageSize=10000&type=date' ,'date='.$timeline->date); ?>
            <?php if($timelist->have()): ?>
                <?php while($timelist->next()): ?>
                <?php endwhile; ?>
            <?php endif; ?>
        <?php endwhile; ?>
    <?php endif; ?>

没有循环出文章

<?php $timelist = $this->widget('Widget_Archive@timeline_'.$timeline->date, '&pageSize=10000&type=date' ,'date='.$timeline->date); ?>

这句我写错了吗?

PHPz
PHPz

学习是最好的投资!

全部回复(2)
阿神

循环是循环啦 貌似没输出啊... echo 出来吧 骚年

ringa_lee

根据年份来循环出归档:

<?php $this->widget('Widget_Contents_Post_Recent', 'pageSize=10000')->to($archives);
    $year=0; $mon=0; $i=0; $j=0;
    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;
    }
    if ($mon != $mon_tmp) {
        $mon = $mon_tmp;
        $output .= '<h3>'. $year .' 年'. $mon .' 月</h3>';
        $output .= '<ul>';
    }
    $output .= '<li><a href="'.$archives->permalink .'">'. $archives->title .'</a>&nbsp;&nbsp;&nbsp;&nbsp;('.date('M j, Y',$archives->created).')</li>';
    endwhile;
    $output .= '</ul>';
    echo $output;
?>
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号