Wednesday, September 30, 2009

Simplepie

I have been using Simplepie for some time. It is great for streaming RSS feeds into your web page. A great way to stream information around when you build your own website.

So what is Simplepie? It is a PHP script that you can install in your web host and configure it to get RSS feeds not only from other website and also from within your website. It also a good way to re-feed the various website and blogs that you have and stream them into one easy to access web page too.

For example if you have Twitter, Flickr, Blogger and your very own website, it would be difficult for your visitor (including yourself for that matter) to keep track of what's happening, so why not provide a single page where all your feeds are channelled into it?

So here comes Simplepie to the rescue! Head on over to the Simplepie.Org website and download the latest PHP script.

I liked Simplepie in the sense that I don't have to set up a SQL database. It is also fairly easy to use, though it may be a little bit more complicated than Feedburner. Between using PHP script vs JavaScript, I would prefer going the way of PHP. The content is both visible to visitors and robot crawlers alike and that is a plus point because the search engine thrives on content.

Upload the simplepie.inc file into your Webserver plus the various files as per their specification.

Then it is time to hack your web page. The file needs to be saved with a .php extension and your server must be able to handle PHP files.

Before the main HTML codes add these php lines

require_once('http://www.example.com/folder/simplepie.inc');
require_once('http://www.example.com/folder/idn/idna_convert.class.php');
$feed = new SimplePie();


Then you need to tell it where to find the feed:

$feed->set_feed_url('http://exampleblog.com/atom.xml');


If you got several feeds, you have to use this line instead. Make sure you do not comma the last feed or you will get errors.

$feed->set_feed_url(array(
'http://www.example1.com/feed1',
'http://www.example2.com/feed2.xml',
'http://www.example3.com/rssfeed3'
));


Init the feed with this line and ready for next step.

$feed->init();


Somewhere in your main page add in the following PHP codes and you are good to go. Modify where necessary for the CSS to format the display.


<?php
foreach ($feed->get_items() as $item):
?>
<div class="item_simplepie">
<h3><a href="<?php echo $item->get_permalink(); ?>" ><?php echo $item->get_title(); ?></a></h3>
<p><?php echo $item->get_description(); ?></p>
<p><small>Posted on <?php echo $item->get_date('j F Y | g:i a'); ?></small></p>
</div>
<?php endforeach; ?>


Easy, yes? That's why it is called Simplepie!

No comments: