Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 22nd, 2010 | Syntax: PHP | Size: 0.99 KB | Hits: 64 | Expires: Never
Copy text to clipboard
  1. <?php
  2. /*
  3. Plugin Name: RSS Shortcode
  4. Version: 0.1
  5. Plugin URI: http://yoast.com/wordpress/rss-shortcode/
  6. Description: Makes it easy to display an RSS feed on a page
  7. Author: Joost de Valk
  8. Author URI: http://yoast.com/
  9. */
  10.  
  11. function yoast_rss_shortcode( $atts ) {
  12.         extract(shortcode_atts(array(  
  13.             "feed"              => '',  
  14.                 "num"           => '5',  
  15.                 "excerpt"       => true
  16.         ), $atts));
  17.         require_once(ABSPATH.WPINC.'/rss.php');  
  18.         if ( $feed != "" && $rss = fetch_rss( $feed ) ) {
  19.                 $content = '<ul>';
  20.                 if ( $num !== -1 ) {
  21.                         $rss->items = array_slice( $rss->items, 0, $num );
  22.                 }
  23.                 foreach ( (array) $rss->items as $item ) {
  24.                         $content .= '<li>';
  25.                         $content .= '<a href="'.esc_url( $item['link'] ).'">'. $item['title'] .'</a>';
  26.                         if ( $excerpt != false && $excerpt != "false") {
  27.                                 $content .= '<br/><span class="rss_excerpt">'. $item['summary'] .'</span>';
  28.                         }
  29.                         $content .= '</li>';
  30.                 }
  31.                 $content .= '</ul>';
  32.         }
  33.         return $content;
  34. }
  35.  
  36. add_shortcode( 'rss', 'yoast_rss_shortcode' );
  37.  
  38. ?>