首页单独调用评论列表

<?php

//start page comments
    $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>";        
    }
//end page comments

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

<ul>

<!--?php include_once "../commlist.php"; ?-->

</ul>

用阿松写的这段代码,修改
$slug = "message"; //页面缩略名
改成
$slug = $this->slug; //页面缩略名

首页文章不用点击进去,也可以单独调用评论列表,但怎么显示评论时间呢?
请高手指点

阅读 1.8k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进