WordPress 中文文档

Function Reference/fetch rss

From WordPress Chinese

Jump to: navigation, search

目录

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
  • ';

    else foreach ( $items as $item ) : ?>

  • <a href='<?php echo $item['link']; ?>' title='<?php echo $item['title']; ?>'> <?php echo $item['title']; ?> </a>
  • <?php endforeach; ?>

%%%

Parameters

Template:Parameterrray.

Related

wp_rss

用户