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

推荐订阅源

博客园 - 司徒正美
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
美团技术团队
WordPress大学
WordPress大学
罗磊的独立博客
Last Week in AI
Last Week in AI
人人都是产品经理
人人都是产品经理
爱范儿
爱范儿
MongoDB | Blog
MongoDB | Blog
J
Java Code Geeks
H
Hackread – Cybersecurity News, Data Breaches, AI and More
H
Help Net Security
S
SegmentFault 最新的问题
C
Check Point Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
腾讯CDC
Engineering at Meta
Engineering at Meta
The GitHub Blog
The GitHub Blog
F
Fortinet All Blogs
D
DataBreaches.Net
雷峰网
雷峰网
GbyAI
GbyAI
宝玉的分享
宝玉的分享

半日闲

不知所措 主题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;
}