时间:2024-03-10
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()
Copyright © 2019-2024 ytldj.com