Posted By

adambundy on 01/08/13


Tagged

rss wordpress


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

adambundy
zemonte


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


 / Published in: PHP
 

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

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

  1. <?php
  2. include_once(ABSPATH . WPINC . '/rss.php');
  3. $feed = 'http://dangayle.com/feed/';
  4. $rss = fetch_feed($feed);
  5. if (!is_wp_error( $rss ) ) :
  6. $maxitems = $rss->get_item_quantity(3);
  7. $rss_items = $rss->get_items(0, $maxitems);
  8. if ($rss_items):
  9. echo "<ul>\n";
  10. foreach ( $rss_items as $item ) :
  11. //instead of a bunch of string concatenation or echoes, I prefer the terseness of printf
  12. //(http://php.net/manual/en/function.printf.php)
  13. printf('<li><a href="%s">%s</a><p>%s</p></li>',$item->get_permalink(),$item->get_title(),$item->get_description() );
  14. endforeach;
  15. echo "</ul>\n";
  16. endif;
  17. endif;
  18. ?>

Report this snippet  

You need to login to post a comment.