Add an RSS Feed to a WordPress Post

For those who aren’t too technically inclined, it can be overwhelming to even think about messing with HTML, let alone try to get certain specialized functions, like embedding an RSS feed within your WordPress blog’s pages or posts, to work. However, here is a step-by-step guide on how to add an RSS feed to your WordPress blog — within a page or post.

A fair word of warning, though — in order for this to work, you need to install the Exec-PHP plugin for WordPress. While installing a plugin shouldn’t be any big deal, the potential side effects for using this plugin could be.

In my experience, using the Exec-PHP plugin requires you to disable the visual editor in your WordPress blog. In turn, this means that once you start using this — you’ll have to rely on WordPress’s simple HTML editor, and not the WYSIWYG HTML editor, to edit, add, and mange, your blogs’ posts and pages.

So, if trying to create a simple HTML link is just too much for you… you might want to consider some alternatives.

This tutorial assumes that you already have an RSS feed lined up. You can use anything, really — Google Blogsearch feeds, Yahoo or Google news RSS feeds, eBay product feeds for your affiliate program, affiliate programs where you’re provided RSS feeds, article directory feeds — it doesn’t much matter. You can add a different RSS feed on every post and page of your website for all that matters — it’s up to you.

In any case — let the fun begin.

Step 1: Download, and install Exec-PHP

This should be self-explanatory — just upload the plugin to your plugins folder.

Step 2: Disable the visual editor in your WP Blog Admin area

To access this option, once you’ve logged into your Wordpress Administration area:

  • On the left panel, under ‘users’, click on ‘Your Profile’
  • Once you are on your profile manager page, at the top, where it says ‘Disable the visual editor while writing’, be sure that is checked.


Insert RSS to Wordpress Blog Post

  • Scroll to the bottom of the page, and press the ‘update profile’ button

Step 3: Create a new page or post

It doesn’t matter which — this will work in both pages and posts

Step 4 Add your feed

This is where it gets a bit tricky, so I’ll walk you through everything once, and then I’ll give you the code to use, and an example setup and show you what your page can look like. So, don’t do anything right this second — just try to absorb what I’m saying.

The first line of the code is just your RSS feeds’ title. It goes in between the apostrophes — write whatever you want here.

1
<h2><?php _e('Your RSS Feed Title'); ?></h2>

The second part is made up of a bunch of parts. What you need to be concerned with is lines 4 and 5.
Line 4 is your RSS feed — notice the link in there — you place your RSS feed link in between the apostrophes
Line 5 is how many items you want to display. Most RSS feeds will limit the number of items they’ll display, but don’t go hog-wild anyway. If you’re showing eBay affiliate feeds or the like, though — 5 is probably too low. Just replace “5″ with whatever number works for you.

2
3
4
5
6
7
<?php // Get RSS Feed(s)
include_once(ABSPATH . WPINC . '/rss.php');
$rss = fetch_rss('http://www.somesite.com/rss.php?show=1234');
$maxitems = 5;
$items = array_slice($rss->items, 0, $maxitems);
?>

The next line represents what you want to show up if the RSS feed doesn’t have anything to display. Just replace ‘nothing here’ with something a bit more friendly.

8
9
<ul>
<?php if (empty($items)) echo '<li>nothing here</li>';

That’s all you need to concern yourself with — that’s all the editing you have to do.

To recap, though — just edit lines 1, 4, 5, and 9 — set them up as you want them, and save your page or post as a draft, and preview your work to be sure it looks, and works, the way you want it to.

The full code is below, and you can see an example of this code in action here: Hulu.com RSS feed.

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<h2><?php _e('Your RSS Feed Title'); ?></h2>
<?php // Get RSS Feed(s)
include_once(ABSPATH . WPINC . '/rss.php');
$rss = fetch_rss('http://www.somesite.com/rss.php?show=1234');
$maxitems = 5;
$items = array_slice($rss->items, 0, $maxitems);
?>
<ul>
<?php if (empty($items)) echo '<li>nothing here</li>';
else
foreach ( $items as $item ) : ?>
<li><a href='<?php echo $item['link']; ?>' title='<?php echo $item['title']; ?>'> <?php echo $item['title']; ?> </a> <br /><?php echo $item['description']; ?>
</li>
<?php endforeach; ?>
</ul>

That’s really all there is to it. Hopefully I kept this simple for you, but simplifying complex things isn’t one of my strongest suits. I can’t dedicate too much time to support, but if you have any questions — post them here. I’ll try to help the best I can.

For the record, though — I did not write this code. I code in Perl — I can’t so much as write a simple redirect script in PHP, though I can debug and tweak it decent enough. So — I didn’t write this code — I found it online somewhere, I used it on a couple of websites, and I know it works. If you know who created this — contact me and let me know — I’ll give credit to whomever wrote it.

Enjoy!

Related Posts:

This entry was posted in Code Examples, How To and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

One Comment

  1. Anna
    Posted December 15, 2009 at 3:46 pm | Permalink

    Thank you, Thank you, THANK YOU!!!! I have been trying to get the ebay rss feed to show on one of my pages in wordpress (self-hosted) for a couple of hours now. But every time I thought I found the solution it would just show a list WITHOUT pictures. Then I posted the above in the page changed things via your instructions and the most beautiful thing showed up…..a page with my ebay rss feed WITH pictures. Okay so it may not be the most beautiful thing but after hours of trying to do it, it seems that way. So again THANK YOU!!!!!!

One Trackback

  1. [...] A brand new resource for internet marketers looking to automate their blog marketing is Auto Post Blogs. While it is brand new, it already has some great resources, such as this post on how to add RSS to your Wordpress Blog. [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

Subscribe without commenting