显示HTML有序列表中的所有RSS项目。
原型
wp_rss( string $url, int $num_items = -1 )
参数
$url
(string)
(Required)
要显示的Feed的网址。不会自动感知Feed网址。
$num_items
(int)
(Optional)
要显示的项目数,默认为全部。
源文件
路径:wp-includes/rss.php
<?php
...
function wp_rss( $url, $num_items = -1 ) {
if ( $rss = fetch_rss( $url ) ) {
echo '<ul>';
if ( $num_items !== -1 ) {
$rss->items = array_slice( $rss->items, 0, $num_items );
}
foreach ( (array) $rss->items as $item ) {
printf(
'<li><a href="%1$s" title="%2$s">%3$s</a></li>',
esc_url( $item['link'] ),
esc_attr( strip_tags( $item['description'] ) ),
esc_html( $item['title'] )
);
}
echo '</ul>';
} else {
_e( 'An error has occurred, which probably means the feed is down. Try again later.' );
}
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/wp_rss/