WordPress: Function Reference/fetch rss:修订间差异

来自站长百科
跳转至: 导航、​ 搜索
无编辑摘要
无编辑摘要
第1行: 第1行:
==Description==
== 描述==
== 描述==
Retrieves an RSS feed and parses it. Uses the [http://magpierss.sourceforge.net/ MagpieRSS and RSSCache] functions for parsing and automatic caching and the [http://sourceforge.net/projects/snoopy/ Snoopy HTTP client] for the actual retrieval.


得到RSS feed并且对其进行解析。使用[http://magpierss.sourceforge.net/ MagpieRSS and RSSCache]函数,为真正的retrieval解析并且自动地储存并且[http://sourceforge.net/projects/snoopy/ Snoopy HTTP client]。
得到RSS feed并且对其进行解析。使用[http://magpierss.sourceforge.net/ MagpieRSS and RSSCache]函数,为真正的retrieval解析并且自动地储存并且[http://sourceforge.net/projects/snoopy/ Snoopy HTTP client]。
==Usage==
== 用法 ==
== 用法 ==
%%% <?php
%%% <?php
include_once(ABSPATH . WPINC . '/rss.php');
include_once(ABSPATH . WPINC . '/rss.php');
$rss = fetch_rss($uri);
$rss = fetch_rss($uri);
?> %%%
?> %%%
%%% <?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:


要得到并且显示当前RSS feed的链接列表,将选项限制为最近的五个:
要得到并且显示当前RSS feed的链接列表,将选项限制为最近的五个:
%%%
<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>
%%%
%%%
%%%
<h2><?php _e('Headlines from AP News'); ?></h2>
<h2><?php _e('Headlines from AP News'); ?></h2>
第78行: 第32行:




==Parameters==
== 参数 ==
== 参数 ==
{{Parameter|$uri|URI|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.}}rray.


{{Parameter|$uri|URI|The URI of the RSS feed you want to retrieve. 返回解析后的feed,items数组中有更有趣而且更有用的位。}}rray.
{{Parameter|$uri|URI|The URI of the RSS feed you want to retrieve. 返回解析后的feed,items数组中有更有趣而且更有用的位。}}rray.


== Related ==
==相关的==
==相关的==
[[WordPress:Function_Reference/wp_rss|wp_rss]]
[[WordPress:Function_Reference/wp_rss|wp_rss]]
[[WordPress:Function_Reference/wp_rss|wp_rss]]

2008年7月26日 (六) 10:09的版本

描述

得到RSS feed并且对其进行解析。使用MagpieRSS and RSSCache函数,为真正的retrieval解析并且自动地储存并且Snoopy HTTP client

用法

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

例子

要得到并且显示当前RSS feed的链接列表,将选项限制为最近的五个: %%%

<?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; ?>

%%%


参数

rray.

相关的

wp_rss