WordPress 中文文档
Function Reference/fetch rss
From WordPress Chinese
目录 |
[编辑]
Description
Retrieves an RSS feed and parses it. Uses the MagpieRSS and RSSCache functions for parsing and automatic caching and the Snoopy HTTP client for the actual retrieval.
[编辑]
Usage
%%% <?php include_once(ABSPATH . WPINC . '/rss.php'); $rss = fetch_rss($uri); ?> %%%
[编辑]
Example
To get and display a list of links for an existing RSS feed, limiting the selection to the most recent 5 items:
%%%
[编辑]
<?php _e('Headlines from AP News'); ?>
<?php // Get RSS Feed(s) include_once(ABSPATH . WPINC . '/rss.php'); $rss = fetch_rss('http://example.com/rss/feed/goes/here'); $maxitems = 5; $items = array_slice($rss->items, 0, $maxitems); ?>
-
<?php if (empty($items)) echo '
- No items ';
- <a href='<?php echo $item['link']; ?>' title='<?php echo $item['title']; ?>'> <?php echo $item['title']; ?> </a>
else foreach ( $items as $item ) : ?>
<?php endforeach; ?>
%%%
[编辑]
Parameters
[编辑]
