On this page
wp_rss( string $url, int $num_items = -1 )
Display all RSS items in a HTML ordered list.
Parameters
$urlstring Required-
URL of feed to display. Will not auto sense feed URL.
$num_itemsint Optional-
Number of items to display, default is all.
Default:
-1
Source
File: wp-includes/rss.php. View all references
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.' );
}
}
Related
Uses
| Uses | Description |
|---|---|
| fetch_rss() wp-includes/rss.php | Build Magpie object based on RSS from URL. |
| _e() wp-includes/l10n.php | Displays translated text. |
| esc_url() wp-includes/formatting.php | Checks and cleans a URL. |
| esc_attr() wp-includes/formatting.php | Escaping for HTML attributes. |
| esc_html() wp-includes/formatting.php | Escaping for HTML blocks. |
Changelog
| Version | Description |
|---|---|
| 1.5.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_rss