I wanted headlines from my blogs to appear on my personal page. And I didn’t want to do a lot of work. Solution?
MagpieRSS to get the headlines, server-side includes to invoke the PHP. First, SSI and PHP.
I’m running apache, so getting SSI required:
a2enmod include
/etc/init.d/apache2 reload
That enables SSI in general.
Next, I added “+Includes” to the appropriate Options line in the sites-enabled file, and added the “XbitHack On” directive. I used XbitHack as a simpler way of enabling SSI instead of renaming files or mapping extensions.
Finally, I added the following code to the personal page (index.html):
<p><!--#include virtual="edgeblog.php" -->
and made index.html executable,
chmod +x index.html
The file edgeblog.php does the not-so-heavy-lifting:
<?php
$path = '/usr/share/php/magpierss';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
include( 'rss_fetch.inc');
$url = 'http://edgekeep.wordpress.com/feed/';
$rss = fetch_rss($url);
foreach ($rss->items as $item ) {
$title = $item[title];
$url = $item[link];
echo "<a href=$url>$title</a></li><br>
";
}
?>
Installing and using MagpieRSS wasn’t as straightforward as I’d hoped. For whatever reason, I could not install it using apt-get directly, so here are the commands in a nutshell, no explanations provided:
wget http://mirrors.kernel.org/ubuntu/pool/universe/m/magpierss/magpierss_0.72-4_all.deb apt-get install libphp-snoopy dpkg -i magpierss_0.72-4_all.deb
You’ll notice that edgeblog.php explicitly adds the magpierss directory to the PHP include path. I don’t know if this is strictly necessary, but I could not (quickly) figure any other way to have my PHP installation notice the existence of Magpie.
In the end, this all required a couple of hours (tops!) research and a couple of minutes execution. Very slick. Probably about the same time as composing this post. :->