Typecho调用最新文章

在制作typecho博客主题时,如果想在网站的侧边栏调用一定数量的博客最新文章列表其实是和WP里差不多的,使用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>

三种形式的代码都差不多。我自己是使用第三种

猜你喜欢

转载自www.cnblogs.com/idid/p/12421794.html