1//start page comments
 2$slug = "message"; //页面缩略名
 3$limit = 10;  //调用数量
 4$length = 30;  //截取长度
 5$ispage = true;  //true 输出slug页面评论,false输出其它所有评论
 6$isGuestbook = $ispage ? " = " : " <> ";
 7
 8$db = $this->db;//Typecho_Db::get();
 9$options = $this->options;//Typecho_Widget::widget('Widget_Options');
10
11$page = $db->fetchRow($db->select()->from('table.contents')
12    ->where('table.contents.status = ?', 'publish')
13    ->where('table.contents.created < ?', $options->gmtTime)
14    ->where('table.contents.slug = ?', $slug));
15
16if( $page ){
17
18    $type = $page['type'];
19    $routeExists = (NULL != Typecho_Router::get($type));
20    $page['pathinfo'] = $routeExists ? Typecho_Router::url($type, $page) : '#';
21    $page['permalink'] = Typecho_Common::url($page['pathinfo'], $options->index);
22
23    $comments = $db->fetchAll($db->select()->from('table.comments')
24    ->where('table.comments.status = ?', 'approved')
25    ->where('table.comments.created < ?', $options->gmtTime)
26    ->where('table.comments.type = ?', 'comment')
27    ->where('table.comments.cid '.$isGuestbook.' ?', $page['cid'])
28    ->order('table.comments.created', Typecho_Db::SORT_DESC)
29    ->limit($limit)  );
30
31    foreach($comments AS $comment) {
32        echo '<li>';
33        echo '<a href="'. $page['permalink']."#comment-".$comment['coid'] .'" title="'.$comment['text'].'">';
34        echo Typecho_Common::subStr(strip_tags($comment['text']), 0, $length, '...').'</a>';
35        echo '</li>';
36    }
37
38}else{
39    echo "<li>No Comments</li>";
40}
41//end page comments

可以将此代码保存为 commlist.php 文件,放在 /usr/themes/ 目录下,在需要调用的主题模板中,输入以下代码

1<ul>
2	<!--?php include_once "../commlist.php"; ?-->
3</ul>