WordPress构建RSS Magpie对象函数:fetch_rss
文 / @WordPress主题
WordPress函数fetch_rss从URL构建基于RSS的Magpie对象,fetch_rss()函数位于rss.php,但自3.0.0版本起,已不建议使用rss.php,因此,推荐使用fetch_feed()函数。
fetch_rss( string $url )
函数参数
$url
字符串
Feed URL地址
函数返回值
成功返回MagpieRSS,失败返回false
MagpieRSS Object ( [parser] => [current_item] => Array ( ) [items] => Array ( [0] => Array ( [title] => WordPress快速添加用户函数:wp_create_user [link] => https://www.tiezhushuo.com/3753.html [dc] => Array ( [creator] => 背字根 ) [pubdate] => Tue, 05 Apr 2022 08:03:20 +0000 [category] => 开发WP函数 [guid] => https://www.tiezhushuo.com/?p=3753 [description] => WordPress函数wp_create_user用于插入新用户,与wp_insert_user()函数相比较 […] [summary] => WordPress函数wp_create_user用于插入新用户,与wp_insert_user()函数相比较 […] ) ...... ) [channel] => Array ( [link] => https://www.tiezhushuo.com [description] => 开发运营笔记 [lastbuilddate] => Tue, 05 Apr 2022 08:04:10 +0000 [language] => zh-CN [sy] => Array ( [updateperiod] => hourly [updatefrequency] => 1 ) [generator] => https://wordpress.org/?v=5.9.3 [tagline] => 开发运营笔记 ) [textinput] => Array ( ) [image] => Array ( [url] => https://www.tiezhushuo.com/wp-content/uploads/2022/04/cropped-favicon-32x32.webp [title] => 背字根 [link] => https://www.tiezhushuo.com [width] => 32 [height] => 32 ) [feed_type] => RSS [feed_version] => 2.0 [stack] => Array ( ) [inchannel] => [initem] => [incontent] => [intextinput] => [inimage] => [current_field] => [current_namespace] => [_CONTENT_CONSTRUCTS] => Array ( [0] => content [1] => summary [2] => info [3] => title [4] => tagline [5] => copyright ) [last_modified] => Tue, 05 Apr 2022 08:04:27 GMT [etag] => [from_cache] => 1 )
函数使用示例
include_once(ABSPATH . WPINC . '/rss.php'); $rss = fetch_rss('https://www.tiezhushuo.com/feed/'); $rss_items = array_slice($rss->items, 0, 5); if(empty($rss_items)) { echo '没有文章'; } else { foreach($rss_items as $item) { echo '<li><a href="' . $item['link'] . '">' . $item['title'] . '</a></li>'; } }
扩展阅读
fetch_rss()函数位于:wp-includes/rss.php
相关函数:
- wp_rss()
- get_rss()

相关文章
-
搭建一个WordPress网站需要多少成本 2023-11-06 00:09:51
-
Symlink介绍(附:如何使用Symlink进行WordPress开发) 2023-11-05 23:38:32
-
让WordPress实现数据库同步的插件:HyperDB 2023-10-24 23:40:49
-
allegro电商平台值得做吗(附:2023年Allegro注册流程指南) 2023-10-08 21:53:39
-
印度跨境电商平台有哪些(附:印度跨境电商做什么产品好) 2023-10-08 21:34:23
-
跨境电商必看的几大海外二手电商平台 2023-10-08 18:04:42
-
WordPress同城互联网产品解决方案:UBASE 2023-10-03 16:40:39
-
WordPress网站的安全插件:wordfence 2023-09-14 09:25:18
-
WordPress 6.3 支持在手动更新插件和主题失败后回滚旧版本 2023-08-28 16:58:45
-
WordPress 6.3版本(2023年8月)性能提升了哪些? 2023-08-28 16:56:02