Wishful Coding

Didn't you ever wish your
computer understood you?

Wordpress RSS widget in a post/page

I'm currently writing a theme for a friend who is going to coach photographers. He wants to have a page that lists RSS feeds from all those photographers. One part of the puzzle is easily solved by using Yahoo! Pipes to combine those feeds, the other part isn't that easy to solve. WordPress comes with a standard RSS widget, but it's only a widget, not a shortcode. There are a bunch of plugins that either offer a RSS widget or turn feeds items into posts. What I did is write my own plugin in only 10 lines of actual code, utilizing the shortcode API and the built-in RSS widget.
  1. Save and upload the snippet below to your plugins folder
  2. Activate it in the WP admin
  3. Add the [rsstag] shortcode to your post or page
  4. Add the feed url like this: [rsstag url="http://pepijn.cqhosting.nl/feed/"]
  5. Save!
You can optionally add one or more of show_summary=1, show_date=1 or show_author=1 to add the respective meta-data to every entry.
php
/*
Plugin Name: Wordpress RSS shortcode
Plugin URI: http://pepijn.cqhosting.nl/2010/06/wordpress-rss-widget-in-a-post-page
Description: This plugin fetches an RSS feed as a shortcode
Author: Pepijn de Vos
Version: 1.0
Author URI: http://pepijn.cqhosting.nl
*/

function rsstag($atts) {
        $atts = shortcode_atts(array(
                'url' => get_bloginfo('rss2_url'),
                'show_author' => 0,
                'show_date' => 0,
                'show_summary' => 0
        ), $atts);
        //var_dump($atts);
        wp_widget_rss_output($atts['url'], $atts);
}
add_shortcode('rsstag', 'rsstag');
?>
I will upload this to WordPress.org soon.