Typecho调用热门评论文章和调用最新文章的方法

Typecho程序在设计主题的时候,侧栏有些时候需要调用热评文章或者最新文章。我们可以在指定的位置通过脚本直接调用。在这篇文章中,陌涛准备整理这个调用文章的方法,以后在有需要的模板中可以直接调用使用。其实设计主题就那么回事,静态模板搞定后,就是直接调用。

第一、最新文章调用

<?php
$this->widget('Widget_Contents_Post_Recent','pageSize=10')->to($recent);
if($recent->have()):
while($recent->next()):
?>
<li><a href="<?php%20$recent->permalink();?>"><?php $recent->title();?></a></li>
<?php endwhile; endif;?>

调用最新10篇文章,可以根据需要修改数值。

第二、调用热评文章

function getHotComments($limit = 10){
$db = Typecho_Db::get();
$result = $db->fetchAll($db->select()->from('table.contents')
->where('status = ?','publish')
->where('type = ?', 'post')
->where('created <= unix_timestamp(now())', 'post')
->limit($limit)
->order('commentsNum', Typecho_Db::SORT_DESC)
);
if($result){
foreach($result as $val){
$val = Typecho_Widget::widget('Widget_Abstract_Contents')->push($val);
$post_title = htmlspecialchars($val['title']);
$permalink = $val['permalink'];
echo '<li><a href="'.$permalink.'" title="'.$post_title.'" target="_blank">'.$post_title.'</a></li>';
}
}
}

在需要的位置出现调用。

原创文章,作者:陌涛,如若转载,请注明出处:https://imotao.com/3397.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
陌涛陌涛
上一篇 2020年7月20日 下午1:40
下一篇 2020年7月20日 下午1:43

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理

docker镜像已更新为 https://0-docker.nat.tf/