Live Category-based OPML template for WordPress 2.0

ok, here’s a little something i’ve been messing with..

i wanted to generate an OPML file based on all the different types of feeds offered with the default WordPress installation. that is, every WP site has a “main” site feed (in rdf, rss, and atom), but there are also category (and subcategory) feeds, as well as feeds for each author. There are even feeds for tags if you use the UTW plugin but i won’t get into that now.

i guess i was originally inspired by the relatively new service offered by Grazr. Add to that the cool things you can do with OPMLBuilder and the awesome potential of Share your OPML..

and well, i got to thinking (more like scheming).

WordPress 2.0 logo
OPML icon
Grazr logo

hmm, the one thing that i couldn’t seem to figure out was why there didn’t seem to be a way to synchronize the feeds in your OPML file and thus ensure that it is always kept up to date. this would make it more useful to me, but i suspect it would be a lot more useful to others too – who in a shared environment (like on Share your OPML) – aren’t necessarily going to know when you add or remove feeds from this your file. essentially, i wanted to be able to create an OPML file, on-the-fly, based on WordPress categorization that would stay current even after i’ve added or deleted categories.

To do this:

  • i created a new WP Template file and called it opml.php
  • i used this new template file to create a WordPress “Page” called opml (you don’t need to put any text in this page just use the OPML Template file (opml.php) instead of the Default Template page and you’re good to go)

What it does:

  • queries the wpdb for all your WP categories (minus any empty categories – ie: ones without posts)
  • excludes any additional categories that you specify (“Uncategorized” is excluded by default)
  • creates a “live” OPML file (actually it’s a URL) based on all your site’s categories but you can easily click on “view source” and copy/paste that code into a local text file (save it as filename.opml)

What you can do with this file:

  • import the OPML into your favorite feedreader (that supports URL imports)
  • create a local OPML file (as described earlier) and import it into your favorite feedreader (that supports OPML file uploads)
  • add your OPML to a directory like Share your OPML ( http://share.opml.org/ )
  • use your OPML to browse your site with Grazr

How to get it all working:

  1. download the new template file from here [ opml.phps ] (right-click and choose “Save Link As..” or “Save Target As..”)
  2. rename opml.phps to opml.php and drop it in your template directory
  3. optionally edit the template file to manually add more categories to the exclude list* (other than the default “Uncategorized”)
  4. create your new WP Page and call it “opml” (you can call it anything but in this case the OPML URL would be http://www.yourdomain.com/opml/)
  5. make sure that permalinks are turned on (otherwise i doubt any of this will work)
  6. try it out in your feedreader, on Share your OPML, or with Grazr

* the exclude list is just a list of category IDs you don’t want to display and formatted as:
$opmlcatid == ’1′ || $opmlcatid == ’2′ || $opmlcatid == ’3′ || and so on..

Examples:

  • you can see it all in action on the Indyish Networking page where visitors can use Grazr to quickly browse the entire site for content, feeds, and more.
  • or, embedded right here in this page

Known Issues:

  • [ resolved: see comments ] i’m not an expert php programmer but for some reason there seems to be a problem when using Grazr (in “Slider” mode) where if you drill down into the category and subcategory feeds – navigating backwards becomes a bit retarded. it goes back to the wrong category and all you see is a completely blank page. Fortunately, you can just keep clicking backward (or the “home” icon, or the “refresh” icon) to get to the top of the directory and start over. Furethermore, i temporarily worked around this problem by switching the default view-mode in Grazr, from “Slider” to “Outline”

Up Next:

  1. i’d like to get it to list all author feeds as well [ Update: this is done. just grab opml-authors.phps, rename it to opml-authors.php, and drop it in your WP template directory. then, uncomment the 2nd to last line of php in opml.php ] *This will only select Users who have the “Author” capability in WordPress. Authors without any published posts are excluded by default. You can also exclude other Authors by manually editing opml-authors.php – similar to the way i described earlier
  2. i’d like to get it to list all Links in WP (ie: the default “Blogroll”, and any other link categories you create in the WP backend) [ Update: this is done. just grab opml-links.phps, rename it to opml-links.php, and drop it in your WP template directory. then, uncomment the last line of php in opml.php ] *you can also exclude Link Categories by manually editing opml-links.php – similar to the way i described earlier
  3. i’d like to get it to be a simple WP plugin

if anyone has time, and wants to take a crack at any of these (or if you see any other ways to improve upon any of this i’d love to hear about it – leave lots of comments)

Comments 5

  1. mikepk wrote:

    Very cool use! This exactly the kind of use we hoped people would begin to explore once we released Grazr 1.0. I’m not positive, but I’m guessing the ‘weirdness’ in the slider mode navigation has to do with the OPML file being generated being invalid. We try *really* hard not to be too anal on what we accept for file format, but sometimes things can get tripped up. The opml you’re generating has a <br /> tag at the end of each <outline> node. Technically this isn’t valid opml (although we should be ignoring it). I’m guessing it’s that extra tag that’s causing the slider to act strange. I’ll look into it some more, but again kudos on the really cool use! Soon, we’re going to set up pages on Grazr.com that highlight neat applications like yours.

    Posted 01 Oct 2006 at 2:24 pm
  2. elran wrote:

    thanks mike,

    i figured the weirdness had to do with the OPML file i was generating so i tried to validate it using OPML Validator Beta and it passed without errors. But now i see that in the KB OPML Validator it fails miserably giving errors due to <br /> tags.

    i have no idea why i put those <br /> tags there in the first place. i guess it was pretty late last night and i started playing around with things too much. i’m going to try things again without the <br /> tags and see if the problem is resolved. i’ll also post about it here in the comments and update the download to reflect any changes.

    keep up the good work @ Grazr !

    Posted 01 Oct 2006 at 2:53 pm
  3. elran wrote:

    ok, that didn’t take long..

    you were right mike. got rid of the <br /> tags – the OPML file validates and Slider now works.

    updates the opml.phps file too!

    thanks again -

    Posted 01 Oct 2006 at 3:01 pm
  4. mikepk wrote:

    I’m glad that fixed it, I’ll also check why we’re not ignoring the <br /> tags. When I get a chance I’m going to put a pointer to this on my blog.

    Posted 02 Oct 2006 at 6:07 pm
  5. Scented Candles wrote:

    Can someone help me create an OPML document with my webpages, not feeds. I need it for products, including bath, candles, soaps, etc.

    Thanks,
    Don

    Posted 27 Oct 2007 at 9:21 pm

Trackbacks & Pingbacks 1

  1. From web 2.0 examples on 17 Dec 2007 at 7:33 am

    web 2.0 examples…

    As usual there is so much talk about Web 2.0 and not many solutions how to really make money with it….

Post a Comment

Your email is never published nor shared. Required fields are marked *