wp_widget_rss_output

Display the RSS entries in a list.

Description

wp_widget_rss_output( (string|array|object) $rss, (array) $args = array() ); 

Parameters (2)

0. $rss (string|array|object)
The rss.
1. $args — Optional. (array) => array()
Widget arguments.

Usage

  1. if ( !function_exists( 'wp_widget_rss_output' ) ) { 
  2. require_once ABSPATH . WPINC . '/widgets.php'; 
  3.  
  4. // The rss. 
  5. $rss = null; 
  6.  
  7. // Widget arguments. 
  8. $args = array(); 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wp_widget_rss_output($rss, $args); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/widgets.php  
  1. function wp_widget_rss_output( $rss, $args = array() ) { 
  2. if ( is_string( $rss ) ) { 
  3. $rss = fetch_feed($rss); 
  4. } elseif ( is_array($rss) && isset($rss['url']) ) { 
  5. $args = $rss; 
  6. $rss = fetch_feed($rss['url']); 
  7. } elseif ( !is_object($rss) ) { 
  8. return; 
  9.  
  10. if ( is_wp_error($rss) ) { 
  11. if ( is_admin() || current_user_can('manage_options') ) 
  12. echo '<p><strong>' . __( 'RSS Error:' ) . '</strong> ' . $rss->get_error_message() . '</p>'; 
  13. return; 
  14.  
  15. $default_args = array( 'show_author' => 0, 'show_date' => 0, 'show_summary' => 0, 'items' => 0 ); 
  16. $args = wp_parse_args( $args, $default_args ); 
  17.  
  18. $items = (int) $args['items']; 
  19. if ( $items < 1 || 20 < $items ) 
  20. $items = 10; 
  21. $show_summary = (int) $args['show_summary']; 
  22. $show_author = (int) $args['show_author']; 
  23. $show_date = (int) $args['show_date']; 
  24.  
  25. if ( !$rss->get_item_quantity() ) { 
  26. echo '<ul><li>' . __( 'Anerrorhas occurred, which probably means the feed is down. Try again later.' ) . '</li></ul>'; 
  27. $rss->__destruct(); 
  28. unset($rss); 
  29. return; 
  30.  
  31. echo '<ul>'; 
  32. foreach ( $rss->get_items( 0, $items ) as $item ) { 
  33. $link = $item->get_link(); 
  34. while ( stristr( $link, 'http' ) != $link ) { 
  35. $link = substr( $link, 1 ); 
  36. $link = esc_url( strip_tags( $link ) ); 
  37.  
  38. $title = esc_html( trim( strip_tags( $item->get_title() ) ) ); 
  39. if ( empty( $title ) ) { 
  40. $title = __( 'Untitled' ); 
  41.  
  42. $desc = @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) ); 
  43. $desc = esc_attr( wp_trim_words( $desc, 55, ' […]' ) ); 
  44.  
  45. $summary = ''; 
  46. if ( $show_summary ) { 
  47. $summary = $desc; 
  48.  
  49. // Change existing [...] to […]. 
  50. if ( '[...]' == substr( $summary, -5 ) ) { 
  51. $summary = substr( $summary, 0, -5 ) . '[…]'; 
  52.  
  53. $summary = '<div class="rssSummary">' . esc_html( $summary ) . '</div>'; 
  54.  
  55. $date = ''; 
  56. if ( $show_date ) { 
  57. $date = $item->get_date( 'U' ); 
  58.  
  59. if ( $date ) { 
  60. $date = ' <span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date ) . '</span>'; 
  61.  
  62. $author = ''; 
  63. if ( $show_author ) { 
  64. $author = $item->get_author(); 
  65. if ( is_object($author) ) { 
  66. $author = $author->get_name(); 
  67. $author = ' <cite>' . esc_html( strip_tags( $author ) ) . '</cite>'; 
  68.  
  69. if ( $link == '' ) { 
  70. echo "<li>$title{$date}{$summary}{$author}</li>"; 
  71. } elseif ( $show_summary ) { 
  72. echo "<li><a class='rsswidget' href='$link'>$title</a>{$date}{$summary}{$author}</li>"; 
  73. } else { 
  74. echo "<li><a class='rsswidget' href='$link'>$title</a>{$date}{$author}</li>"; 
  75. echo '</ul>'; 
  76. $rss->__destruct(); 
  77. unset($rss);