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.