Typecho Wiki
每一个作品都值得被记录

Typecho 调用指定数量最新文章的方法代码

Typecho维基君Typecho教程 • 2557次浏览 • 发布 2018-06-09 • 更新 2018-06-09
极致加速的V2Ray 助您畅享全球网络 & 搬瓦工VPS最新优惠码
🛜自用大流量超低月租手机卡推荐榜单 #拒绝流量焦虑

在制作两栏typecho博客主题时,如果想在网站的侧边栏调用一定数量的博客最新文章列表怎么办?方法很简单,使用Widget_Contents_Post_Recent这个widget即可调用,通过pageSize参数即可限制调用数量。

代码一

<?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} – 文章标题

代码二

<?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;?>

代码三

<?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

广告声明:文内含有的对外跳转链接(包括不限于超链接、二维码、口令等形式),用于传递更多信息,节省甄选时间,结果仅供参考,Typecho.Wiki所有文章均包含本声明。
本文检索关键词:typecho
厂商投放

【腾讯云】🎉五一云上盛惠!云服务器99元/月续费同价!

腾讯云五一劳动节海量产品 · 轻松上云!云服务器首年1.8折起,买1年送3个月!超值优惠,性能稳定,让您的云端之旅更加畅享。快来腾讯云选购吧!

广告
添加新评论 »