Creating a RSS Feed Reader for WordPress
Have you ever wondered if thereās a way to create a page that displays all your friendsā recent entries so you donāt have to visit their sites individually every time you want to see if they have updates? Well, I have created just the post for you. I still need to find a way to display full entries though, and possibly categories the entries fall under, the authorās name, and a comments link with the number of comments already posted. Basically, Iām looking for something like Livejournalās friends page or Xangaās subscriptions page.
Hereās the bit of PHP code you will be needing:
<?php
require_once (ABSPATH . WPINC . '/rss-functions.php');
$url = 'http://sue.com/feed/';
$rss = fetch_rss( $url );
if ( $rss ) {
echo "<h4>" . $rss->channel['title'] . "</h4>";
$i = 1;
foreach ($rss->items as $item) {
$href = $item['link'];
$title = $item['title'];
$pubdate = $item['pubdate'];
$author = $item['author'];
$category = $item['category'];
$description = $item['description'];
echo "<span style="font-size:16px">$title</span><b>$pubdate</b><div style="padding:0 20px;">$description</div>";
if ($i == 1 ) break;
$i = $i + 1;
}
}
?>
The only part you really need to change is the part that says
http://sue.com/feed/
Change that to whatever URL the feed page is to your friendās web site. Usually they provide a link for you. If you have Firefox, you can view that page by clicking on the orange square icon on the very right of the address bar. Otherwise you can right click and view source to find where it says link rel=āalternateā and find the URL of the feed after that. Be sure it ends with rss, or feed. Somehow atom feeds donāt work with this code.
For each new feed URL you want on the page, youāll need to copy and paste that code again and insert the URL.
Edit on 1.30.2008: To display full entry feeds, use this bit of code in place of where it says
$description = $item['description'];
$isset = $item['content']['encoded'];
and replace where it says $description with $isset.
To display the authorās name use this:
$author = $item['dc']['creator'];
And be sure to include echo āAuthor: $authorā;
Oh yeah, and here are the instructions for how to apply the code:
To set up the dailies page, you need to create a template. Letās call it āFeedā. To create a template, basically copy the code from page.php or if you donāt have that use index.php, but delete wherever they call the comments function, the date, and anything else you donāt want to show up on your dailies page.
Create feed.php with that copied code from page.php or index.php. At the top you should write _
<?php /* Template Name: Feed */ ?>
or whatever you want the template name to be. Then you should paste that bit of code I mentioned in this post in place of where it says _
<?php the_content(); ?>
or something similar to that.
Create as many duplicates of that bit of code as there are feeds you want to read from people. It only creates one entry per site. Be sure to replace the URL with whatever feed URL you want. After that, save the feed.php, and upload it on your server under your themeās folder.
Then create a page in WordPress, and name it āDailiesā or something like that. Be sure to select the template āFeedā. You donāt have to write anything on that page. Hit publish, and you should be able to view that page.