get_rss() - WordPress 函数参考中文文档

返回介绍

get_rss()

发布于 2017-09-11 字数1812 浏览 959 评论 0

get_rss( string $url,  int $num_items = 5 )

Display RSS items in HTML list items.


描述

You have to specify which HTML list you want, either ordered or unordered before using the function. You also have to specify how many items you wish to display. You can’t display all of them like you can with wp_rss() function.


参数

$url

(string)
(Required)
URL of feed to display. Will not auto sense feed URL.

$num_items

(int)
(Optional)
Number of items to display, default is all.

Default value: 5


返回值

(bool) False on failure.


源代码

File: wp-includes/rss.php

function get_rss ($url, $num_items = 5) { // Like get posts, but for RSS
	$rss = fetch_rss($url);
	if ( $rss ) {
		$rss->items = array_slice($rss->items, 0, $num_items);
		foreach ( (array) $rss->items as $item ) {
			echo "<li>\n";
			echo "<a href='$item[link]' title='$item[描述]'>";
			echo esc_html($item['title']);
			echo "</a><br />\n";
			echo "</li>\n";
		}
	} else {
		return false;
	}
}

更新日志

Version 描述
1.5.0 Introduced.

相关函数

Uses

  • wp-includes/formatting.php:
    esc_html()
  • wp-includes/rss.php:
    fetch_rss()

User Contributed Notes

上一篇:get_role()

下一篇:get_sample_permalink()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!