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

推荐订阅源

美团技术团队
D
DataBreaches.Net
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
D
Docker
N
Netflix TechBlog - Medium
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
Check Point Blog
腾讯CDC
Stack Overflow Blog
Stack Overflow Blog
V
Visual Studio Blog
IT之家
IT之家
月光博客
月光博客
U
Unit 42
K
Kaspersky official blog
T
Threatpost
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
GbyAI
GbyAI
P
Proofpoint News Feed
Last Week in AI
Last Week in AI
云风的 BLOG
云风的 BLOG
酷 壳 – CoolShell
酷 壳 – CoolShell
I
InfoQ
Engineering at Meta
Engineering at Meta
Recorded Future
Recorded Future
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Security @ Cisco Blogs
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
Security Archives - TechRepublic
Security Archives - TechRepublic
Webroot Blog
Webroot Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
S
Schneier on Security
S
Secure Thoughts
The Register - Security
The Register - Security
B
Blog RSS Feed
The Last Watchdog
The Last Watchdog
P
Palo Alto Networks Blog
爱范儿
爱范儿
B
Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
L
LINUX DO - 热门话题
C
Cisco Blogs
Spread Privacy
Spread Privacy
F
Full Disclosure
博客园 - 聂微东
T
The Blog of Author Tim Ferriss

半日闲

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