Untitled
By: a guest | Mar 22nd, 2010 | Syntax:
PHP | Size: 0.99 KB | Hits: 64 | Expires: Never
<?php
/*
Plugin Name: RSS Shortcode
Version: 0.1
Plugin URI: http://yoast.com/wordpress/rss-shortcode/
Description: Makes it easy to display an RSS feed on a page
Author: Joost de Valk
Author URI: http://yoast.com/
*/
function yoast_rss_shortcode( $atts ) {
extract(shortcode_atts(array(
"feed" => '',
"num" => '5',
"excerpt" => true
), $atts));
require_once(ABSPATH.WPINC.'/rss.php');
if ( $feed != "" && $rss = fetch_rss( $feed ) ) {
$content = '<ul>';
if ( $num !== -1 ) {
$rss->items = array_slice( $rss->items, 0, $num );
}
foreach ( (array) $rss->items as $item ) {
$content .= '<li>';
$content .= '<a href="'.esc_url( $item['link'] ).'">'. $item['title'] .'</a>';
if ( $excerpt != false && $excerpt != "false") {
$content .= '<br/><span class="rss_excerpt">'. $item['summary'] .'</span>';
}
$content .= '</li>';
}
$content .= '</ul>';
}
return $content;
}
add_shortcode( 'rss', 'yoast_rss_shortcode' );
?>