欢迎光临卢大叔的自留地!
本站已稳定运行13年362天
双击窗口标题可以返回顶部
底部导航显示不全时可以左右滑动
备案号:京ICP备16065789号-5
卢大叔的自留地
2023,加糖,去冰 !
Typecho提供了根据时间维度来获取文章归档的api,
[Widget_Contents_Post_Date]$obj = $this->widget('Widget_Contents_Post_Date');
if($obj->have()){
while($obj->next()){
$obj->date();
... ...
}
}else{
echo '无文章';
}
Widget_Contents_Post_Date字段解析year:年份的字符串形式,譬如2015
month:月份的字符串形式,譬如01
day:字符串形式
date:字符串形式,具体格式由format参数指定,譬如参数指定为Y-m,则date字段输出2015-01
count:该时间归档下的文章数目
permalink:该时间归档的地址
譬如var_dump($obj)可能输出一下内容:array (size=6)
'year' => string '2015' (length=4)
'month' => string '01' (length=2)
'day' => string '25' (length=2)
'date' => string '2015-01' (length=7)
'count' => int 12
'permalink' => string 'http://www.typechodev.com/index.php/2015/01/' (length=46)
Widget_Contents_Post_Date可用参数format 设定输出格式,譬如参数指定为Y-m,则date字段输出2015-01。
type 设定归档类型,默认是month
limit 查询的条数,默认为0,则不限制,输出所有。
$this->widget('Widget_Contents_Post_Date','format=Y-m&type=month&limit=0')`,表示按月份为最小维度进行归档,展示的格式是Y-m,并显示所有归档。
Widget_Contents_Post_Date常见用法
常规用法
通过widget方法初始化组件,并使用next()进行迭代。
$this->widget('Widget_Contents_Post_Date')->to($recent);
while($recent->next()):
......
endwhile;
快捷用法
使用便捷方法
parse:$this->widget('Widget_Contents_Post_Date')->parse('{date}(count)');