导航菜单

需求

仿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();