OPML Sidebar for WordPress

22 November 2005 by Dan

If you look in the right column running down the main page of this website (the sidebar), you'll notice a heading for my "Blogroll." And if you examine the blogroll, you may notice this little graphic OPML graphic that says OPML. That's because my blogroll is being generated on-the-fly from my OPML reading lists generated by PodNova and NewsGator.

Here is the PHP code for the OPML sidebar and the XSL stylesheet that generates an HTML list for the blogroll.

To use this hack, you'll need to save opmlSidebar.php in your theme directory. You'll also need to create two subdirectories in your theme directory, _cache and xsl, and save opmlSidebar.xsl in the xsl subdirectory. You will probably need to change the directory permissions of the _cache directory to be world readable and world writeable (i.e., CHMOD 777).

In addition, somewhere in your sidebar.php file (or whatever file it is in your theme that generates your sidebar), you'll need to add code something like this for each OPML file you want to include:

<li><h2>Blogroll</h2>
<?php
{
include('opmlSidebar.php');
$xslfile = dirname(__FILE__).'/xsl/opmlSidebar.xsl';
$opmlfile = '{URL FOR YOUR OPML FILE}';
$opmlname = '{NAME FOR YOUR OPML FILE}';
$file = checkCache($opmlfile);
renderOPML($file, $opmlfile, $xslfile);
?>
<?php
}
?>
</li>

I only recently started using WordPress, so I haven't had time to get into the Plugin API, yet. But I wanted to publicize this hack.

Please leave a comment if you want to discuss this hack.

9 comments to “OPML Sidebar for WordPress”

  1. jtintle:

    This looks like an interesting hack. I have just started trying to understand OPML and how it will do anything for me...now I found a way to add it to my WP site...thank you

  2. Dan:

    Thanks, jtintle. I hope you find this useful. Please let me know about your experience using it.

  3. Library clips :: Active blogrolls! :: December :: 2005:

    [...] Another alternative is to use an OPML sidebar script, what this does is load a blog roll onto a blog sidebar already filed in categories, this is importing an outline into a blog via the OPML file…see here (in this example the outline is not made in an outlining tool, but it is an RSS reader which I suppose is an outline of feeds in categories). [...]

  4. jtintle:

    Ok I finally got around to trying this out on my test WP blog at http://jtintle.com/. I just can't seem to get the the blogrolls to expand. Seems we would also need the ExpandCollapse script maybe.

  5. jtintle:

    ok I found the expand script by looking at your source...it works just trying to modify it a bit for what i want to use it for

  6. frEdSCAPEs:

    Onderhoudt je Blogroll in OPML

  7. Dan:

    Jtintle - I've been tweaking this a bit, but I've yet to update my post to reflect the changes. In fact, I'm going to revise the XSL to generate the JavaScript. It'll be more portable that way. Stay tuned.

  8. jtintle:

    You betcha, I'll keep an eye out,plus I have you in my sage feeds.
    Now I just have to figure a way to have my WP blog automatically create a OPML file of my posts

  9. Dan:

    I'm closing comments here and referring everyone to the plugin page: OPML Renderer.