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

Typecho 单独调用评论列表自定义评论列表页

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

Typecho单独调用评论列表的代码,自定义评论列表页

<?php
/**
* 单独页面调用评论列表
*
* @author Mr.Asong
*/
$slug = "message"; //页面缩略名
$limit = 10; //调用数量
$length = 30; //截取长度
$ispage = true; //true 输出slug页面评论,false输出其它所有评论
$isGuestbook = $ispage ? " = " : " <> ";
 
$db = $this->db; //Typecho_Db::get();
$options = $this->options; //Typecho_Widget::widget('Widget_Options');
 
$page = $db->fetchRow($db->select()->from('table.contents')
->where('table.contents.status = ?', 'publish')
->where('table.contents.created < ?', $options->gmtTime)
->where('table.contents.slug = ?', $slug));
 
if ($page) {
$type = $page['type'];
$routeExists = (NULL != Typecho_Router::get($type));
$page['pathinfo'] = $routeExists ? Typecho_Router::url($type, $page) : '#';
$page['permalink'] = Typecho_Common::url($page['pathinfo'], $options->index);
 
$comments = $db->fetchAll($db->select()->from('table.comments')
->where('table.comments.status = ?', 'approved')
->where('table.comments.created < ?', $options->gmtTime)
->where('table.comments.type = ?', 'comment')
->where('table.comments.cid ' . $isGuestbook . ' ?', $page['cid'])
->order('table.comments.created', Typecho_Db::SORT_DESC)
->limit($limit));
 
foreach ($comments AS $comment) {
echo '<li>';
echo '<a href="' . $page['permalink'] . "#comment-" . $comment['coid'] . '" title="' . $comment['text'] . '">';
echo Typecho_Common::subStr(strip_tags($comment['text']), 0, $length, '...') . '</a>';
echo '</li>';
}
} else {
echo "<li>No Comments</li>";
}
//不需要结束标志,并空一行

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

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

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

广告
添加新评论 »