Advertisements

wp_widget_rss_output

Definition:
function wp_widget_rss_output( $rss, $args = array() {}

Display the RSS entries in a list.

Parameters

  • string|array|object $rss: RSS url.
  • array $args: Widget arguments.

Source code

function wp_widget_rss_output( $rss, $args = array() ) {

	if ( is_string( $rss ) ) {

		$rss = fetch_feed($rss);

	} elseif ( is_array($rss) && isset($rss['url']) ) {

		$args = $rss;

		$rss = fetch_feed($rss['url']);

	} elseif ( !is_object($rss) ) {

		return;

	}



	if ( is_wp_error($rss) ) {

		if ( is_admin() || current_user_can('manage_options') )

			echo '<p>' . sprintf( __('<strong>RSS Error</strong>: %s'), $rss->get_error_message() ) . '</p>';

		return;

	}



	$default_args = array( 'show_author' => 0, 'show_date' => 0, 'show_summary' => 0 );

	$args = wp_parse_args( $args, $default_args );

	extract( $args, EXTR_SKIP );



	$items = (int) $items;

	if ( $items < 1 || 20 < $items )

		$items = 10;

	$show_summary  = (int) $show_summary;

	$show_author   = (int) $show_author;

	$show_date     = (int) $show_date;



	if ( !$rss->get_item_quantity() ) {

		echo '<ul><li>' . __( 'An error has occurred; the feed is probably down. Try again later.' ) . '</li></ul>';

		$rss->__destruct();

		unset($rss);

		return;

	}



	echo '<ul>';

	foreach ( $rss->get_items(0, $items) as $item ) {

		$link = $item->get_link();

		while ( stristr($link, 'http') != $link )

			$link = substr($link, 1);

		$link = esc_url(strip_tags($link));

		$title = esc_attr(strip_tags($item->get_title()));

		if ( empty($title) )

			$title = __('Untitled');



		$desc = str_replace( array("\n", "\r"), ' ', esc_attr( strip_tags( @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option('blog_charset') ) ) ) );

		$desc = wp_html_excerpt( $desc, 360 );



		// Append ellipsis. Change existing [...] to [&hellip;].

		if ( '[...]' == substr( $desc, -5 ) )

			$desc = substr( $desc, 0, -5 ) . '[&hellip;]';

		elseif ( '[&hellip;]' != substr( $desc, -10 ) )

			$desc .= ' [&hellip;]';



		$desc = esc_html( $desc );



		if ( $show_summary ) {

			$summary = "<div class='rssSummary'>$desc</div>";

		} else {

			$summary = '';

		}



		$date = '';

		if ( $show_date ) {

			$date = $item->get_date( 'U' );



			if ( $date ) {

				$date = ' <span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date ) . '</span>';

			}

		}



		$author = '';

		if ( $show_author ) {

			$author = $item->get_author();

			if ( is_object($author) ) {

				$author = $author->get_name();

				$author = ' <cite>' . esc_html( strip_tags( $author ) ) . '</cite>';

			}

		}



		if ( $link == '' ) {

			echo "<li>$title{$date}{$summary}{$author}</li>";

4273

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: