Return to Snippet

Revision: 61700
at January 8, 2013 03:29 by adambundy


Initial Code
<?php
include_once(ABSPATH . WPINC . '/rss.php');
$feed = 'http://dangayle.com/feed/';
$rss = fetch_feed($feed);
if (!is_wp_error( $rss ) ) :
        $maxitems = $rss->get_item_quantity(3);
    $rss_items = $rss->get_items(0, $maxitems);
    if ($rss_items):
        echo "<ul>\n";
        foreach ( $rss_items as $item ) : 
            //instead of a bunch of string concatenation or echoes, I prefer the terseness of printf 
            //(http://php.net/manual/en/function.printf.php)
            printf('<li><a href="%s">%s</a><p>%s</p></li>',$item->get_permalink(),$item->get_title(),$item->get_description() );
        endforeach;
        echo "</ul>\n";
    endif;
endif;
?>

Initial URL
http://www.dangayle.com/import-feeds-wordpress-fetch-feed/

Initial Description
Thanks Dan Gayle.
http://www.dangayle.com/import-feeds-wordpress-fetch-feed/

Initial Title
Wordpress - get an RSS feed, display items with a loop

Initial Tags
wordpress

Initial Language
PHP