Insert RSS Feed Into WP Page
I wanted to include an RSS feed from a wordpress website into on of its own pages for a newsletter that was being sent out. Turns out, though, you don’t need to do this and can just query the custom post type, haha.
On a site note, yes, this is basically the same script as the demo they provide you with in the WP codex. For some reason it wasn’t working for me until I edited it into this form…
Include this somewhere before the script at the top of the page (I put mine in the template declaration):
<?php /* Template Name: Newsletter*/ include_once(ABSPATH . WPINC . '/feed.php'); ?>
Here’s the script:
Go Back<?php
$rss = fetch_feed(‘http://www.url.com/feed/?post_type=news’);
if (!is_wp_error( $rss ) ) :
$maxitems = $rss->get_item_quantity(7);
$rss_items = $rss->get_items(0, $maxitems);
endif;if ($maxitems == 0 ) echo $rss->get_error_message();
else
foreach ( $rss_items as $item ) :
echo ‘<h2><a href=”‘.$item->get_permalink().’”>’.$item->get_title().’</a></h2>’;
echo ‘<p>’.$item->get_description().’<a href=”‘.$item->get_permalink().’” class=”more-link”>Read More…</a></p>’;endforeach; ?>