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

来自站长百科
跳转至: 导航、​ 搜索
(新页面: ==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://sourc...)
 
无编辑摘要
第1行: 第1行:
==Description==
==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.  
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]。


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


%%% <?php
%%% <?php
第11行: 第22行:


==Example==
==Example==
== 例子 ==


To get and display a list of links for an existing RSS feed, limiting the selection to the most recent 5 items:
To get and display a list of links for an existing RSS feed, limiting the selection to the most recent 5 items:
要得到并且显示当前RSS feed的链接列表,将选项限制为最近的五个:


%%%
%%%
第34行: 第49行:
</ul>
</ul>
%%%
%%%
%%%
<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>
%%%


==Parameters==
==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. 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.


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

2008年7月21日 (一) 10:51的版本

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.

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

Usage

用法

%%% <?php include_once(ABSPATH . WPINC . '/rss.php'); $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的链接列表,将选项限制为最近的五个:

%%%

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

%%%




%%%

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

参数

rray.

rray.

Related

相关的

wp_rss wp_rss