tutorials web

Display external RSS feeds on your WordPress blog

Show another of your blogs or any other RSS news feed on your WordPress blog with this simple template code.

Open your template file in either the WordPress admin editor or via FTP/SSH access to your hosting server. If you want to put the feed links in your sidebar either look for a sidebar.php or similar file.

Locate where you want to include the feed and add the following code:

python
:::php
<?php include_once(ABSPATH.WPINC.'/feed.php');
$rss = fetch_feed('http://root.abl.es/rss/latest/');
$maxitems = $rss->get_item_quantity(5);
$rss_items = $rss->get_items(0, $maxitems);
?>
<ul>

<?php if ($maxitems == 0) echo '<li>No items.</li>';

else

// Loop through each feed item and display each item as a hyperlink.

foreach ( $rss_items as $item ) : ?>

<li>

<a href='<?php echo $item->get_permalink(); ?>'

title='<?php echo 'Posted '.$item->get_date('j F Y | g:i a'); ?>'>

<?php echo $item->get_title(); ?></a>

</li>

<?php endforeach; ?>

</ul>

You will want to modify the code as follows: Change the fetch_feed URL to your own blog (or show ours!). Change the get_item_quantity(5) to the number of items you wish to show.

Save the file and refresh your blogpage. You should now see the feed entries in your page!

Over 10,000 developers have bought Create GUI Applications with Python & Qt!
Create GUI Applications with Python & Qt6
More info Get the book

Downloadable ebook (PDF, ePub) & Complete Source code

To support developers in [[ countryRegion ]] I give a [[ localizedDiscount[couponCode] ]]% discount on all books and courses.

[[ activeDiscount.description ]] I'm giving a [[ activeDiscount.discount ]]% discount on all books and courses.