wp_rss() WordPress Function
The wp_rss() function is used to retrieve and display RSS feeds from WordPress. RSS is a popular syndication format used by many websites and blogs. WordPress supports RSS feeds out of the box, and the wp_rss() function makes it easy to display them on your site. This function takes two parameters: the RSS feed URL and an optional array of arguments. The URL is the only required parameter, and it should be a valid RSS feed. The array of arguments is optional, but it can be used to customize the behavior of the function. The wp_rss() function will return an error if the URL is not a valid RSS feed. Otherwise, it will return an array of RSS items. Each RSS item will have a title, link, and description. You can use these items to display the RSS feed on your site.
wp_rss( string $url, int $num_items = -1 ) #
Display all RSS items in a HTML ordered list.
Parameters
- $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: -1
Source
File: wp-includes/rss.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.' ); } }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
1.5.0 | Introduced. |