<?php // Get RSS Feed(s)
include_once( ABSPATH . WPINC . '/feed.php' );
// Get a SimplePie feed object from the specified feed source.
$rss = fetch_feed( 'https://www.youtube.com/channel/UCZEUuBtKIvoZPSQMgtKUw5A' );
// $rss = fetch_feed( 'http://www.forbes.com/taxes-law/feed2/', 'http://www.wsj.com/xml/rss/3_7031.xml' );
/*
$rsslist = array( 'http://www.forbes.com/taxes-law/feed2/',
'http://www.wsj.com/xml/rss/3_7031.xml',
'http://www.taxlawroundup.com/?feed=rss'
);
$rss = fetch_feed($rsslist);
*/
$maxitems = 0;
if ( ! is_wp_error( $rss ) ) : // Checks that the object is created correctly
// Figure out how many total items there are, but limit it to 5.
$maxitems = $rss->get_item_quantity( 7 );
// Build an array of all the items, starting with element 0 (first element).
$rss_items = $rss->get_items( 0, $maxitems );
endif;
?>
<?php if ( $maxitems == 0 ) : ?>
<ul>
<li><?php _e( 'No items', 'my-text-domain' ); ?></li>
</ul>
<?php else : ?>
// Loop through each feed item and display each item as a hyperlink.
<?php foreach ( $rss_items as $item ) :
echo '<div class="rss-feed-container">';
if ($enclosure = $item->get_enclosure())
{
echo '<img class="feed-thumb" style="float: left; width: 200px; margin-right: 10px;" src="' . $enclosure->get_thumbnail() . '" />';
}
?>
<a title="<?php printf( __( 'Posted %s', 'my-text-domain' ), $item->get_date('j F Y | g:i a') ); ?>" href="<?php echo esc_url( $item->get_permalink() ); ?>" target="_blank" rel="noopener">
<?php echo esc_html( $item->get_title() ); ?></a> - <?php echo esc_html( $item->get_date('F j, Y') ); ?>
<p><?php echo substr($item->get_description(), 0, 150); ?> <a title="<?php echo esc_html( $item->get_title() ); ?>" href="<?php echo esc_url( $item->get_permalink() ); ?>">Continue Reading</a></p>
<?php echo '</div>'; ?>
<?php endforeach; ?>
<?php endif; ?>
RSS Aggregator Code To Pull RSS Feed Content On Your Page Manually
[updated_on]
[updated_on]
Share this post:
Share this post:
Featured
Top Guides
- Yoast SEO On-Page SEO
- MailChimp Setup & WordPress Integration
- How To Hide WordPress "Footprint"
- Keyword Research for 2018 & Beyond
8 thoughts on “RSS Aggregator Code To Pull RSS Feed Content On Your Page Manually”
Let’s do this
Yes, let’s!
Hello,
I want to show custom post type content is it possible. if possible please give me a code.
Hi Raju,
Do you mean creating an RSS feed for a custom post type or adding custom fields to an existing RSS feed?
Depending on how you want to modify the feeds these two could be helpful. If you’re happy with adding the content of these feeds to the content area of the feed, then this will be helpful http://www.paulund.co.uk/add-custom-fields-to-rss-feed.
If you want to modify the feed in some other way then I suggest you look at this https://codex.wordpress.org/Customizing_Feeds
I hope that helps and thanks for stopping by!
This is brilliant! How often does it refresh the feed, is it on page load? Thanks!
Hi Yari,
Yes the feed is refreshed on page load. But there will be no new content of the target site didn’t publish new content.
Hey, love your youtube channel! I’m trying to use your code in a custom template file however it doesn’t seem to be working. Is there any chance you could help me out a little with this? im working off of a dev domain as the site is not ready to launch as of yet.
currently developing on: http://elmers.cornerstone-dev.co.uk/
trying to pull in a news feed via: http://elmersbigparadesuffolk.co.uk/?cat=2&feed=rss2
if you could shed some light i would be very grateful 🙂
Hi Steve,
I tested the code on the wp-phd.com demo site and the code below worked:
get_item_quantity( 7 );
// Build an array of all the items, starting with element 0 (first element).
$rss_items = $rss->get_items( 0, $maxitems );
endif;
?>
<?php foreach ( $rss_items as $item ) :
echo '
if ($enclosure = $item->get_enclosure())
{
echo ‘
}
?>
get_permalink() ); ?>” title=”get_date(‘j F Y | g:i a’) ); ?>” target=”_blank”>
get_title() ); ?> – get_date(‘F j, Y’) ); ?>
get_description(), 0, 150); ?>
get_permalink() ); ?>” title=”get_title() ); ?>”>Continue Reading
<?php echo '
‘; ?>
I don’t know the exact reason it worked for me and not for you. The error on your development site says that the URL is invalid, have you double checked that you have the correct URL there?