偶然逛大神的网站看到这个觉得可以用到自己网站上..
把“记刻”页面上的评论调用到首页做个滚动的公告栏或者展示..
<?php
$slug = "links"; //独立页面缩略名
$limit = 8; //调用评论数量
$length = 30; //截取文字长度
$ispage = true; //true 输出页面评论,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>";
}
?>
在需要展示的地方贴上代码即可..
本文由 Jdeal 创作,转载自jdeal.cn。