php - typecho怎么获取某个人的评论列表

查看:181
本文介绍了php - typecho怎么获取某个人的评论列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

typecho中,可以获取最新的评论列表

那么如果我只想获取 某个人的评论列表,例如作者的评论,怎么实现。

解决方案

typecho自带的评论组件不包含自定义作者的功能。你可以自行扩展,下面给出详细代码。
如果可以用,请采纳。

在你的主题的functions.php中加入以下代码,以默认主题default为例:

class Widget_Comments_RecentPlus extends Widget_Abstract_Comments
{
    /**
     * 构造函数,初始化组件
     *
     * @access public
     * @param mixed $request request对象
     * @param mixed $response response对象
     * @param mixed $params 参数列表
     * @return void
     */
    public function __construct($request, $response, $params = NULL)
    {
        parent::__construct($request, $response, $params);
        $this->parameter->setDefault(array('pageSize' => $this->options->commentsListSize, 'parentId' => 0, 'ignoreAuthor' => false));
    }

    /**
     * 执行函数
     *
     * @access public
     * @return void
     */
    public function execute()
    {
        $select  = $this->select()->limit($this->parameter->pageSize)
        ->where('table.comments.status = ?', 'approved')
        ->order('table.comments.coid', Typecho_Db::SORT_DESC);

        if ($this->parameter->parentId) {
            $select->where('cid = ?', $this->parameter->parentId);
        }

        if ($this->options->commentsShowCommentOnly) {
            $select->where('type = ?', 'comment');
        }
        
        /** 忽略作者评论 */
        if ($this->parameter->ignoreAuthor) {
            $select->where('ownerId <> authorId');
        }

        if ($this->parameter->mail) {
            $select->where('mail = ?', $this->parameter->mail);
        }

        $this->db->fetchAll($select, array($this, 'push'));
    }
}

在sidebar.php中修改对应内容如下,其中test@qq .com就是你对应的需要显示的人的邮箱,注意是Widget_Comments_RecentPlus不是Widget_Comments_Recent

    <section class="widget">
        <h3 class="widget-title"><?php _e('最近回复'); ?></h3>
        <ul class="widget-list">
        <?php $this->widget('Widget_Comments_RecentPlus', 'mail=test@qq.com')->to($comments); ?>
        <?php while($comments->next()): ?>
            <li><a href="<?php $comments->permalink(); ?>"><?php $comments->author(false); ?></a>: <?php $comments->excerpt(35, '...'); ?></li>
        <?php endwhile; ?>
        </ul>
    </section>

这篇关于php - typecho怎么获取某个人的评论列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆