Typecho调用指定数量最新文章的方法代码
时间:2020-08-01 阅读:359
在制作两栏typecho博客主题时,如果想在网站的侧边栏调用一定数量的博客最新文章列表怎么办?方法很简单,使用Widget_Contents_Post_Recent
这个widget即可调用,通过pageSize参数即可限制调用数量。
代码一
1 2 3 | <?php $this->widget('Widget_Contents_Post_Recent','pageSize=10')->parse('<li><a href="{permalink}"><span>{year}/{month}/{day}</span>{title}</a></li>'); ?> |
参数说明:
pageSize – 要调用的文章数量,默认调用后台“设置-阅读-文章列表数目”里设置的数量
{permalink} – 文章链接标签代码
{year} – 文章发布时间年份
{month} – 文章发布时间月份
{day} – 文章发布时间天
{title} – 文章标题
代码二
1 2 3 4 5 6 7 | <?php $this->widget('Widget_Contents_Post_Recent','pageSize=10')->to($recent);if($recent->have()):while($recent->next()):?><li><a href="<?php $recent->permalink();?>"><?php $recent->title();?></a></li><?php endwhile; endif;?> |
代码三
1 2 3 4 5 6 7 | <?php $recent = $this->widget('Widget_Contents_Post_Recent','pageSize=10');if($recent->have()):while($recent->next()):?> <li><a href="<?php $recent->permalink();?>"><?php $recent->title();?></a></li><?php endwhile; endif;?> |
提示:把代码pageSize=10
中的10为要调用的文章数量。
函数位于var/Widget/Contents/Post/Recent.php
文章由 博客吧 整理发布
网友评论