惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 叶小钗
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
雷峰网
雷峰网
GbyAI
GbyAI
Hugging Face - Blog
Hugging Face - Blog
N
Netflix TechBlog - Medium
博客园 - 聂微东
Y
Y Combinator Blog
罗磊的独立博客
博客园_首页
小众软件
小众软件
有赞技术团队
有赞技术团队
爱范儿
爱范儿
F
Fortinet All Blogs
C
Check Point Blog
Google DeepMind News
Google DeepMind News
云风的 BLOG
云风的 BLOG
Apple Machine Learning Research
Apple Machine Learning Research
M
MIT News - Artificial intelligence
月光博客
月光博客
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 司徒正美
aimingoo的专栏
aimingoo的专栏

半日闲

不知所措 主题XaInk支持Typecho1.3 Typecho仿百度响应式主题Xaink XA Note - 小A笔记 2025总结 又是一年1024程序员节 outlook账号保证安全必要的修改 如何申请并cf托管免费域名ip6.arpa 铭记历史、缅怀先烈、珍爱和平、开创未来 再上阳台山 Typecho用户注册后的邮件验证插件 Typecho同步分享文章到telegram频道插件PostToTelegram
Typecho1.3文章永久链接获取
小A · 2026-02-10 · via 半日闲

在原来 Typecho1.2 中可以通过以下方式获取热门文章(评论数排序)

function GetHotPosts($limit = 10)
{
    $db = Typecho_Db::get();
    $select  = $db->select()->from('table.contents')
        ->where("table.contents.password IS NULL OR table.contents.password = ''")
        ->where('table.contents.status = ?','publish')
        ->where('table.contents.created <= ?', time())
        ->where('table.contents.type = ?', 'post')
        ->limit($limit)
        ->order('table.contents.commentsNum', Typecho_Db::SORT_DESC);
    $result = $db->fetchAll($select, array(Typecho_Widget::widget('Widget_Abstract_Contents'), 'push'));
    return $result;
}

但是 Typecho_Widget::widget('Widget_Abstract_Contents'), 'push') 在最新的 Typecho1.3 中不再支持,会获取不到文章的永久链接 permalink

使用官方推荐的函数 Helper::widgetById() 来获取文章永久链接,可以兼容 1.2 和 1.3 。

function GetHotPosts($limit = 10)
{
    $db = Typecho_Db::get();
    $select  = $db->select()->from('table.contents')
        ->where("table.contents.password IS NULL OR table.contents.password = ''")
        ->where('table.contents.status = ?','publish')
        ->where('table.contents.created <= ?', time())
        ->where('table.contents.type = ?', 'post')
        ->limit($limit)
        ->order('table.contents.commentsNum', Typecho_Db::SORT_DESC);
    $rows = $db->fetchAll($select);
    $result = [];
    foreach ($rows as $row) {
        $cid = $row['cid'];
        $post = Helper::widgetById('Contents', $cid);
        $result[] = [
            'cid' => $cid,
            'title' => $post->title,
            'permalink' => $post->permalink
        ];
    }
    return $result;
}