typecho获取当前作者的全部评论

本文阅读 2 分钟
广告

参考文章:typecho怎么获取某个人的评论列表
因为看到很多博客的个人中心都有文章和评论,刚好本站也有个人中心,于是也想用typecho实现,百度找到了参考文章。

多次测试使用下来发现了个缺点,函数是根据邮箱获取的评论,如果用户更改了邮箱,之前使用原邮箱的评论就不会显示。甚至会出现作者A修改成作者B的邮箱,输出作者B的评论。

于是开始琢磨,进入数据库查看,发现comments表里是有authorId字段的,也就是说是可以实现根据作者id输出评论的,这样的好处就是不用理会作者的邮箱。不会出现以上说出的缺点。实现起来也比较容易。
实现方法

/*输出作者发表的评论*/
class Widget_Post_AuthorComment extends Widget_Abstract_Comments
{
    public function execute()
    {
        global $AuthorCommentId;//全局作者id
        $select  = $this->select()->limit($this->parameter->pageSize)
        ->where('table.comments.status = ?', 'approved')
        ->where('table.comments.authorId = ?', $AuthorCommentId)//获取作者id
        ->where('table.comments.type = ?', 'comment')
        ->order('table.comments.coid', Typecho_Db::SORT_DESC);//根据coid排序
        $this->db->fetchAll($select, array($this, 'push'));
    }
}

使用方法

<?php
global $AuthorCommentId;//全局作者id
$AuthorCommentId=$this->authorId;//获取作者id
?>
<?php $this->widget('Widget_Post_AuthorComment@index','pageSize=15')->to($AuthorComment); ?>
<?php while($AuthorComment->next()): ?>
//这里是代码
<li><a href="<?php $AuthorComment->permalink() ?>"><?php $AuthorComment->excerpt(50, '...'); ?></a></li>
<?php endwhile; ?>
本文来自投稿,不代表本站立场,如若转载,请注明出处:https://www.ruletree.club/archives/1584/
typecho通过qq邮箱显示k值qq头像,且不暴露QQ号
« 上一篇 02-28
杰奇cms几个不常见但很实用的区块调用方式
下一篇 » 03-04
广告

发表评论

V注册会员 L评论等级
R2 条回复
  1. 火喵Lv.1 说道:
    2022-05-02     Win 10 /    Chrome

    本打算借用大佬的代码,在循环中增加一个显示回复用户评论的内容的功能,但是失败了,好难啊qaq

  2. 默契Lv.1 说道:
    2020-03-05     iPhone /    Safari

    能写个文章收藏功能吗

    1. 不暇VLv.6 说道:
      2020-03-05     Android /    Chrome

      @默契

      有时间可以尝试一下

没有更多评论了

作者信息

热门文章

标签TAG

热评文章