Create a WordPress Archive for posts in Multiple Categories

By Glenn Ansley  |  November 11th, 2009  |  Published in WordPress, WordPress Plugins  |  1 Comment

One of my first experiences with the social web was Del.icio.us. I stopped using it shortly after Yahoo! aquired it, but that’s a different story. The reason I bring it up is because I loved the way that you could search for multiple tags by including a + sign in between each tag in the URL. Can you even do that anymore?

So, I’ve been wanting to do this with WordPress categories for a while now and recently had the motivation to make it happen (aka: a client needed it).
Below is my first draft. It only works with permalink structures for now. I’m looking for some feedback and ‘beta testing’ before I put it into the WordPress plugin repository. Would anyone like to help?

How it currently works:

  1. Download, unzip, FTP to your site’s plugins folder.
  2. Activate the plugin.
  3. Visit http://yourdomain.com/categories/cat1-slug+cat2-slug+cat-3slug+etc/
  4. You should get a listing of all your current posts that are in all of the above categories.

Templates, Titles, etc

I am currently using the following logic for determining what theme file is used to display your posts:

  1. If there is a file called categories.php, use that.
  2. If there is a file called archive.php, use that.
  3. If there is a file called index.php, use that.
  4. If there is a file called 404.php, use that.

I currently have the following functions available to help you build a title for your archive page

  1. is_categories() returns true if you are on a categories page ie: /categories/ is in the URL
  2. ft_mca_titles() returns an array of titles for each of the categories in your URL

Download the zip file here: ft-multiple-category-archives.php.

Leave comments below. Thanks!

Responses

  1. Demetris says:

    November 11th, 2009 at 7:07 pm (#)

    I think many people will find this plugin useful. I tried it and it works as advertised. A couple of questions/observations:

    1. Is there a technical reason that the base is different than the category base used in the blog? (And if you use a custom category base, the difference in more than singular/plurar. For example I usually use “cat” or “topic” as a category base.)

    2. It adds a trailing slash to the URLs, although I do not use one in my permalink structure. For example, I type:

    http://example.com/categories/foo+bar

    … and the URL changes to:

    http://example.com/categories/foo+bar/

    Cheers!

    PS. You can still do that in Del.icio.us. I do it all the time for my tags. :-)

Leave a Response