Typecho侧边栏最新评论实现显示评论于文章功能

Typecho教程 2020-05-10 84℃ 2 0

需求

仿WordPress主题的是否发现Typecho的侧边栏评论列表没有这样的功能。只能自己实现了

实现

其实观察comments表就发现该表有cid字段,就是评论所属文章,那侧边栏评论的Widget_Comments_Recent可以直接调用cid

echo $comments->cid; // 文章cid

那就好说了,直接一个SQL语句查询就行了。

以下代码放到functions.php就能用

public function getParent($cid)
{
    $select = $this->db->select()->from('table.contents')->where('table.contents.cid = ?', $cid)->limit(1);
    $result = $this->db->fetchAll($select);
    if (isset($result[0])) {
        return Typecho_Config::factory($result[0]);
    }
    return Typecho_Config::factory(array());
}

使用方式也很简单

getParent($comments->cid)->title();

评论 (2)

  • 学到了,Typecho_Config::factory(array()); 还能这么用。(p.s.只有一条数据,为什么不用fetch()呢?)

    回复
    • 都是从已有代码改,fetchrow改动有点多

      回复
友情链接
最近评论
  1. Thiết kế phòng hát karaoke : I got this website from my pal who told me on the topic of this site and now this time I am visiting this site and
    reading very informative articles or reviews here.
  2. Lil Durk : Hello I am so grateful I found your website, I really found you by accident, while
    I was researching on Google for something else, Regardless I am here now and would just like to say
    thanks for a marvelous post and a all round exciting
    blog (I also love the theme/design), I don’t have time to read it all at the moment but I have book-marked it and also
    added your RSS feeds, so when I have time I will be back to read more, Please do keep up the superb b.
  3. Sbobet99 : Howdy thiiѕ is kinda of off tօpic but Ι was wondering if blogs use
    WYSIWYG editors or if you have to manually code with HTML.I'm starting a blog so᧐n butt have no coding skills so I wantеd to get guidаnce
    from someone with experience. Any help would be enormously аpprecіated!
  4. choithethao.tips : Undeniably believe that which you said. Your favorite
    justification seemed to be on the net the easiest thing to be aware of.
    I say to you, I certainly get irked while people consider
    worries that they plainly don't know about. You managed to
    hit the nail upon the top and also defined out the whole thing without having side-effects ,
    people can take a signal. Will likely be back to get more.Thanks
  5. https://veviewwii.tumblr.com/post/662643202115944448/ml-18s21-t2-2 : Link exchange is nothing else however it is simply placing the other
    person's web site link on your page at suitable place and other person will also do similar in support of
    you.
Top