WordPress as CMS – Sections + Categories = Filtering Fun!

By Sol in Lab

Well, that wasn’t so hard after all 🙂

Displaying items in a section filtered by a category is now working!

I was thinking it was going to be harder because I was initially thinking I was going to go with Worpress’ default category functions to display categorized items, which I would then have to figure out how to filter the results by the current section. I decided to first try the other route, and used my current implementation of fetching items belonging to a specific section and added in some category filtering code if a category was passed via the URL. This worked out quite well and thankfully didn’t take very time to implement at all.

So if you navigate to: http://domain.com/section-name/category/category-name, it will display only those categories in “section-name“, which are also assigned to the “category-name” category.

It works with categories and sub-categories equally well. As each category is actually its own row in the DB, all that’s necessary when looking-up sub-categories is to get the last category listed in the query string (e.g. domain.com/section-name/category/cat/subcat/ will get items assigned to subcat). In fact, it doesn’t matter what any of the text before the final category in the query string, because currently the script only looks at the last word. Also, the script checks to make sure that the extracted category text is actually a category. If it isn’t a valid category, the query will return all items in the section. Later, I may add some iteration to display items from the parent category if the sub-category is not a valid category.

The nice thing about breaking up the categories passed via the query string is that it also opens up the possibility for fancy intersections of categories/tags, etc. This is nice because it’s the intersections that I like most about tagging systems (such as finding all posts matching “WordPress” and “CMS“)

Also, on the topic of customized RSS templates, I realized that I could generate customized RSS feeds within the plugin itself, thus avoiding having to deal with WordPress’ default RSS templates. The RSS format is simple enough, and is quite strict, so I wouldn’t have to worry too much about writing a feed generator for any situation. By doing this, the default RSS feeds generated by WordPress would work as usual, and I could happily create any custom feeds I wanted as well. I guess this will be my next task.

With these latest features added to the plugin, I’m finally starting to feel like I’m nearing a level of functionality where I would consider this plugin “usable“. I still have a bit more to do to standardize everything (function names, etc.), and make it simple to implement in themes (i.e. template tags). Hopefully, just a few more refinements and I’ll be able to release the first version of this plugin. Then I can get on to add some real functionality! 🙂