<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>gHacks technology news &#187; simplepie</title>
	<atom:link href="http://www.ghacks.net/tag/simplepie/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ghacks.net</link>
	<description>A technology blog covering software, mobile phones, gadgets, security, the Internet and other relevant areas.</description>
	<lastBuildDate>Tue, 24 Nov 2009 16:29:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Display Cached RSS Feed In Your Website</title>
		<link>http://www.ghacks.net/2009/05/06/display-cached-rss-feed-in-your-website/</link>
		<comments>http://www.ghacks.net/2009/05/06/display-cached-rss-feed-in-your-website/#comments</comments>
		<pubDate>Wed, 06 May 2009 11:44:23 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[rss feed]]></category>
		<category><![CDATA[simplepie]]></category>
		<category><![CDATA[web dev]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[websites]]></category>

		<guid isPermaLink="false">http://www.ghacks.net/?p=12615</guid>
		<description><![CDATA[You might remember the announcement of our new web project Appnews which basically displays software updates in a friendly easily accessible way. What I wanted to do now is to display the five newest items of the RSS feed in the sidebar of this blog to both promote the appnews service but also provide a [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.ghacks.net/wp-content/uploads/2009/05/rss.jpg" alt="rss" title="rss" width="128" height="128" class="alignleft size-full wp-image-12614" />You might remember the announcement of our new web project <a href="http://www.appnews.net/">Appnews</a> which basically displays software updates in a friendly easily accessible way. What I wanted to do now is to display the five newest items of the RSS feed in the sidebar of this blog to both promote the appnews service but also provide a new service to my readers as they would be able to see the software updates immediately in the sidebar. What I needed was a high traffic friendly way of displaying the RSS feed and that meant caching. Without caching the script would request the contents on every page hit which would slow down the web server tremendously.</p>
<p><span id="more-12615"></span>One of the better scripts to display cached RSS feeds in a website is SimplePie. It might look a bit intimidating at first glance as it provides lots of options to customize the display. It is however very easy to display a feed with just a few lines of code. Start by downloading <a href="http://simplepie.org/">SimplePie</a> from the website. Extract it to the computer system and upload it to the root folder of the website. You should also create a directory called <em>cache</em> in that root folder and make it writeable (chmod to 777).</p>
<p>Now add the following two lines to the top of the php file where you want to display the feed in. The first line defines the location of the simplepie.inc file on the web server (which is in the simplepie directory in root), the second the feed that you want to display on the website.</p>
<p><code>&lt;?php <br />
include_once $_SERVER['DOCUMENT_ROOT'] . '/simplepie/simplepie.inc'; <br />
$feed = new SimplePie('http://feedproxy.google.com/Ghacksnet');<br />
?&gt;</code></p>
<p>Now place the following code in the location on the website where the feed should be displayed. This will fetch the five newest feed items and display them in the selected location.</p>
<p><code>&lt;ul&gt;<br />
&lt;?php foreach ($feed-&gt;get_items(0, 5) as $item): ?&gt;<br />
    &lt;li&gt;<br />
        &lt;a href=&quot;&lt;?php print $item-&gt;get_permalink(); ?&gt;&quot;&gt;<br />
        &lt;?php print $item-&gt;get_title(); ?&gt;&lt;/a&gt;<br />
    &lt;/li&gt;<br />
&lt;?php endforeach; ?&gt;<br />
&lt;/ul&gt;</code></p>
<p>And that&#8217;s it. SimplePie offers a wealth of additional functions and settings to display more than one feed or mix feeds. The default caching time is 60 minutes.</p>

	Tags: <a href="http://www.ghacks.net/tag/php/" title="php" rel="tag">php</a>, <a href="http://www.ghacks.net/tag/rss-feed/" title="rss feed" rel="tag">rss feed</a>, <a href="http://www.ghacks.net/tag/simplepie/" title="simplepie" rel="tag">simplepie</a>, <a href="http://www.ghacks.net/tag/web-dev/" title="web dev" rel="tag">web dev</a>, <a href="http://www.ghacks.net/tag/web-development/" title="web development" rel="tag">web development</a>, <a href="http://www.ghacks.net/tag/websites/" title="websites" rel="tag">websites</a><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.ghacks.net/2009/02/01/web-development-php-what-role-does-it-fill/" title="Web Development: PHP &#8211; what role does it fill (February 1, 2009)">Web Development: PHP &#8211; what role does it fill</a> (1)</li>
	<li><a href="http://www.ghacks.net/2009/02/16/php-what-it-does-and-what-it-doesnt/" title="PHP &#8211; what it does and what it doesn&#8217;t (February 16, 2009)">PHP &#8211; what it does and what it doesn&#8217;t</a> (4)</li>
	<li><a href="http://www.ghacks.net/2009/03/16/web-development-roundup/" title="Web development roundup (March 16, 2009)">Web development roundup</a> (1)</li>
	<li><a href="http://www.ghacks.net/2009/03/09/scriptastique-web-development-roundup/" title="Scriptastique web development roundup (March 9, 2009)">Scriptastique web development roundup</a> (4)</li>
	<li><a href="http://www.ghacks.net/2008/10/26/publish-rss-news-feeds-on-twitter/" title="Publish RSS News Feeds On Twitter (October 26, 2008)">Publish RSS News Feeds On Twitter</a> (6)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ghacks.net/2009/05/06/display-cached-rss-feed-in-your-website/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
