There are times when you want to display external RSS feed on your blog. Perhaps a blog feed of your another blog or some other site. Well you do not need a plugin to do this because WordPress have a function built in that will take care of this. In this article we will show you how you can display an external RSS feed on your blog. This way you can even use WordPress as a news aggregator.
Simply paste the following code in any WordPress file that you choose. Preferrably in a custom page that you create.
01 | <h2><?php _e( 'Recent news from Some-Other Blog:' , 'my-text-domain' ); ?></h2> |
04 | include_once ( ABSPATH . WPINC . '/feed.php' ); |
09 | if ( ! is_wp_error( $rss ) ) : |
12 | $maxitems = $rss ->get_item_quantity( 5 ); |
15 | $rss_items = $rss ->get_items( 0, $maxitems ); |
21 | <?php if ( $maxitems == 0 ) : ?> |
22 | <li><?php _e( 'No items' , 'my-text-domain' ); ?></li> |
25 | <?php foreach ( $rss_items as $item ) : ?> |
27 | <a href= "<?php echo esc_url( $item->get_permalink() ); ?>" |
28 | title= "<?php printf( __( 'Posted %s', 'my-text-domain' ), $item->get_date('j F Y | g:i a') ); ?>" > |
29 | <?php echo esc_html( $item ->get_title() ); ?> |
Make sure you change the feeds url and the quantity and any other setting that you like.