WordPress

Publish External Feeds in Your WordPress Site

Some folks don’t realize it, but WordPress has integrated the ability to publish other feeds with some out of the box features. I’ve written in the past on how to publish a blog’s feed to give a boost to a site’s keyword density for improved search engine optimization – but this is how to do it right within WordPress.

WordPress has embedded Magpie and RSS Caching within its available function, fetch_feed:

  • fetch_feed — retrieve an RSS feed from a URL with automatic caching (included in rss_functions.php)

If you’d like to, for example, add our latest 5 posts to your site (as we did on DK New Media):

<?php // Get RSS Feed(s)
include_once( ABSPATH . WPINC . '/feed.php' );
$rss = fetch_feed(‘http://feed.martech.zone');
if ( ! is_wp_error( $rss ) ) :
$maxitems = $rss->get_item_quantity( 5 );
$items = array_slice($rss->get_items, 0, $maxitems);
endif;
?>

<ul>
<?php if (empty($items)) echo '<li>No items</li>';
else
foreach ( $items as $item ) : ?>
<li><a href='<?php echo esc_url( $item->get_permalink() ); ?>'
title='<?php printf( __( 'Posted %s', 'my-text-domain' ), $item->get_date('j F Y | g:i a') ); ?>'>
<?php echo esc_html( $item->get_title() ); ?>
</a></li>
<?php endforeach; ?>
<?php endif; ?>
</ul>

Edit your WordPress template (Design > Theme Editor) and place the code where you’d like the feed to publish. There are also a ton of sidebar widgets out there that will publish feeds for you as well.

4 Comments

  1. 1

    You can republish your own content, too, not just others. I’ve done this for a while at SMJdesign since all it is a blog that is an aggregation of my four blogs. I prefer using FeedList plugin instead of the built in RSS functionality.

    You can use this for a Twitter sideblog or anything that has an RSS feed!

    • 2

      Good to see you on the circle, Stephen! Curious of the advantages of the plugin over the built in features? Is it simply the interface? I like the fact that caching is built into the internal function – for high volume days/sites, that could come in handy!

      Cheers!
      Doug

  2. 3

    Brilliant – this is exactly what I need! I’ve been working on a WP MU site and I simply want the main blog to just show a page with a nice graphic for each of the blogs. Now, I can add in a couple posts under each graphic rather than have them hang out on the sidebar using the RSS widget.

    • 4

      Awesome, William!

      The funny part is I was half-way down the road of implementing MagPie when I decided to check the WP site out to see how others might be doing it. Those folks at WP really do a fantastic job, don’t they?

      Doug

Leave a Reply