OPML Pages and OPML Sidebar Revisions

OPML Sidebar Revisions

I made some revisions to my OPML sidebar hack.

I added a more graceful failure when the checkCache function cannot retreive the OPML file, and I also changed the $maxage variable so that its value can be passed via the function call.

In addition, I changed the HTML output to be expandable/collapsible lists. The javascript for this feature is generated by the XSL stylesheet. N.B. Be sure to drop some images in your images subdirectory and edit the XSL to set the appropriate variables to point to your images.

Most importantly, I've renamed the file from opmlSidebar.php to opmlHtmlXslRenderer.php. Why? Because I'm also using it to generate pages in WordPress!

Here are the revised opmlHtmlXslRenderer.php and the revised opmlSidebar.xsl. To take advantage of the more graceful error handling, modify your template to call opmlHtmlXslRenderer.php something like this:

<li><h2>Reading Lists</h2>
    < ?php
    {
    require_once("opmlHtmlXslRenderer.php");
    $xslfile = dirname(__FILE__).'/xsl/opmlSidebar.xsl';
    $opmlfile = '{URL FOR YOUR OPML FILE}';
    $opmlname = '{NAME FOR YOUR OPML FILE}';
    $file = checkCache($opmlfile);
    if (empty($_ENV['checkCacheError'])) {
        renderOPML($file, $opmlfile, $xslfile);
        ?><div class="blogrollButton"><a href="<?php echo $opmlfile ?>"><img src="<?php echo bloginfo('stylesheet_directory') . '/images/opml.jpg'?/>" alt="< ?php echo $opmlname ?>" title="<?php echo $opmlname ?>" /></a><br /></div>
        < ?php
        }
    ?>
</li>

OPML Pages

Now, if you want to generate WordPress pages from an OPML file (or multiple files) you'll need to create a new page template. Here's the OPML page template I've created and here's the opmlPages.xsl XSLT stylesheet to transform the OPML to HTML. opmlPages.xsl is very similar to opmlSidebar.xsl, the main difference being that the former does not encode the html entities, thus permitting any markup to display properly on the page (you've been warned).

I'm assuming you know how to write a page in WordPress. For each OPML page, the page content should be {TITLE YOU WANT TO DISPLAY}, {FILENAME OF OPML FILE}. You can include multiple OPML files by separating each comma-delimited entry with a semicolon. You can separate multiple semicolon-delimited entries with spaces or line breaks. You may not use a comma or semicolon in the title or filename (this is a slap-together hack, not enterprise software).

Take a look at my examples: To Do and New Software and Hardware. The former demonstrates including two OPML files, and the latter demonstrates the mutliple levels of expanding/collapsing nodes.

It's that easy. The design is up to you. And I strongly recommend you use only OPML files located on your server -- that way, you can shorten your maximum cache age since you won't be fetching remote URLs all the time.

Note that if you're using Dave Winer's OPML Editor, you can add my ftpUpstream script and automatically upload your OPML files to your server.

4 thoughts on “OPML Pages and OPML Sidebar Revisions

  1. I noticed you have a collapse/expand feature on your reading lists

    Is it possible to expand to a further level by previewing the latest posts from each blog in your reading list?

  2. John, that's certainly possible. But I'm not sure I want to turn my blog into portal. There are tons of RSS aggregators out there -- Magpie RSS is good for integrating into PHP-based sites, such as WordPress, and it includes a fully functional cache system to reduce bandwidth consumption. In fact, now that you mention it, I think I'd like to use that to "integrate" my OPML blog into this blog. Hmmm... yet another diversion...

    But if your question was about XSL, you could add one more level to the remote feeds right in the XSL stylesheet, but that would not cache those feeds. So that would (1) slow down your site tremendously and (2) hammer those feeds beyond belief, even with only moderate site traffic, as every page load would call every feed in your list. It would be an efficient way to make enemies, at least!

Comments are closed.