This tutorial is meant to show you how to include SimplePie into your 68 Classifieds site.
SimplePie is a very fast and easy-to-use class, written in PHP, that puts the ’simple’ back into ‘really simple syndication’. Flexible enough to suit beginners and veterans alike, SimplePie is focused on speed, ease of use, compatibility and standards compliance.
Step 1.
Download SimplePie. For this tutorial I used v1.2
Step 2.
Upload simplepie.inc to “includes/simplepie” directory. If this folder does not exist you should create it. Next make the cache directory in your sites root writable.
Step 3.
Now we are going to do the actual integration. For the purpose of this tutorial we will just hard code into the index.php file so it is only available on the home page. Of course you can put this in init or a plugin to make it global. But we are going for simple.
Open index.php file and add this to process the feed with SimplePie:
include_once('includes/simplepie/simplepie.inc');
$feed = new SimplePie();
$feed->set_feed_url('http://feeds.feedburner.com/EricLBarnes');
$success = $feed->init();
$feed->handle_content_type();
foreach($feed->get_items() as $item)
{
$rss['title'] = $item->get_title();
$rss['link'] = $item->get_link();
$rss['date'] = $item->get_date();
$items[] = $rss;
}
$class_tpl->assign('rss_feed', $items);
The code above pulls in the rss for this site and loops through the items and assigns it to the “$items” array. Finally it assigns $items to the template as a variable named $rss_feed. You can change $feed->set_feed_url to your own rss feed.
Step 4.
Now open your home.tpl template file and at the bottom add this code:
<h3>Feed</h3>
<ul>
{foreach from=$rss_feed item="entry"}
<li>
<a href="{$entry.link}">{$entry.title}</a> - {$entry.date}
</li>
{/foreach}
</ul>
Once that is added you can save the template and then view your sites home page. Hopefully you will have a nice list of latest entries from the rss feed. Of course you can format it better and also pull out more information than what is shown. If you wish for more details please consult the SimplePie Documentation.
