扫码关注官方订阅号
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中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
typecho自带的评论组件不包含自定义作者的功能。你可以自行扩展,下面给出详细代码。
如果可以用,请采纳。
在你的主题的functions.php中加入以下代码,以默认主题default为例:
在sidebar.php中修改对应内容如下,其中test@qq .com就是你对应的需要显示的人的邮箱,注意是Widget_Comments_RecentPlus不是Widget_Comments_Recent