wordpress获取rss内容的函数wp_rss、fetch_rss

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:


<h2><?php _e('Headlines from AP News'); ?></h2>
<?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->items0$maxitems);
?>

<ul>
<?php if (empty($items)) echo '<li>No items</li>';
else
foreach ( 
$items as $item ) : ?>
<li><a href='<?php echo $item['link']; ?>
title='<?php echo $item['title']; ?>'>
<?php echo $item['title']; ?>
</a></li>
<?php endforeach; ?>
</ul>

Parameters

$uri
(URI) (required) The URI of the RSS feed you want to retrieve. The resulting parsed feed is returned, with the more interesting and useful bits in the items array.

Default: Nonerray.

Description

Retrieves an RSS feed and parses it, then displays it as an unordered list of links. 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-functions.php');
wp_rss($uri$num);
?> 

Example

To get and display a list of 5 links from an existing RSS feed:

<?php 
include_once(ABSPATH WPINC '/rss-functions.php');
wp_rss('http://example.com/rss/feed/goes/here'5);
?>

Parameters

$uri
(URI) (required) The URI of the RSS feed you want to retrieve. The resulting parsed feed is returned, with the more interesting and useful bits in the items array.

Default: None
$num
(integer) (required) The number of items to display.

Default: None

Output

The output will look like the following:

<ul>
<li>
<a href='LINK FROM FEED' title='DESCRIPTION FROM FEED'>TITLE FROM FEED</a>
</li>
(repeat for number of links specified)
</ul>

柳华芳
柳华芳

奔向光明之地

文章: 1202
订阅评论
提醒
guest

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据

0 评论
内联反馈
查看所有评论
0
希望看到您的想法,请您发表评论x