-
-
Save dangayle/7dd8a245658c80c136a4 to your computer and use it in GitHub Desktop.
The correct way to import feeds into WordPress using fetch_feed()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment