常用函数-fetch_rss()

0条评论

常用函数-fetch_rss()

说明

检索某个RSS订阅并进行解析。用 MagpieRSS and RSSCache进行解析并自动缓存,用 Snoopy HTTP 客户端

进行实际检索。

用法

<?php
include_once(ABSPATH . WPINC . '/rss.php');
$rss = fetch_rss($uri);
?> 

示例

要获取并显示已有RSS订阅的链接列表,可以将选择项限制在最近5项以内:

 

<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->items, 0, $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>

参数

$uri

(URI)(必需)希望检索的RSS订阅的URI。返回结果被检索的feed,以及iterms 数组中有实用价值的二进制数。

默认值:Nonerray

相关资源

wp_rss

发表新评论

此内容将保密,不会被其他人看见。
  • 自动将网址与电子邮件地址转变为链接。
  • 允许HTML标签:<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • 自动断行和分段。

更多关於格式化选项的信息

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.