排行榜 统计
  • 建站日期:2020/07/11
  • 文章总数:151 篇
  • 评论总数:184 条
  • 分类总数:5 个
  • 最后更新:1月17日

Typecho调用单独页面评论代码

本文阅读 1 分钟
首页 typecho 正文

本文最后更新于2022年12月23日, 已超过488天没有更新。 如果文章内容或图片资源失效,请留言反馈,我会及时处理,谢谢!

<?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>

转载于:MR.ASONG

本文来自投稿,不代表本站立场,如若转载,请注明出处:
-- 展开阅读全文 --
有一种伤害,叫冷淡
« 上一篇 10-04
给Typecho编辑文章页添加标签tags选择表
下一篇 » 10-08