Fun with Categories
Fun with Categories is a WordPress plugin that was written to provide the option to list posts that fall into both of two named categories instead of just one.
The plugin was written to provide a specific functionality, in a specific way, for a specific site, and amended for general use.
Version
Version 0.3 - January 8th 2008 - First General Release
Installation
Save fun-with-categories.php into wp-content/plugins/ and activate using the admin options.
How it works
To display post filtered by two categories you must use one the following permalink structures:
http://www.yoursite.com/categories/category1name/category2name/
http://www.yoursite.com/index.php/categories/category1name/category2name/
It doesn’t matter which way round they are in order to work; however, if you want to make the category titles display consistently then you might want to make sure you always put them the same way round.
Templates
This plugin will look to see if there is a template file called categories.php in your theme folder. If not it will check for archive.php and failing that will revert to index.php as usual.
Conditional Tags
To compliment the existing conditional tags this plugin adds the following:
is_dual_categories()
This returns true or false to determine if the posts are being filtered by two categories.
Example:
if ( is_dual_categories() ) { echo 'Now filtering by dual categories'; }
Include Tags
To compliment the existing functionality the following have been added
dual_cat_titles();
This is the dual category equivalent to single_cat_title() used on the archive page.
By default this outputs both category names with “and” between them.
There are two options:
Which category:
show the first (1) , second (2), or both (0) categories:
dual_cat_titles(1)
Between:
If showing both categories choose the text to go between them (including spaces):
dual_cat_titles(0, ' and ')
An example of its use:
The URL reads: http://www.mysite.com/index.php/categores/india/photographs/
The code reads:
<strong><?php dual_cat_titles(2) ?> from <?php dual_cat_titles(1) ?></strong>
The page displays: Photographs from India
Download
Download the plugin from WordPress Extend
- Permalink
- Andrew Rickmann
- 8 Jan 2008 10:50 PM
- Comments (11)
February 13th, 2008 at 10:49 pm
I really like this idea. However I cannot get it to work. It never filtters the results though it says two categories have been selected:
_ from _
Outputs on my screen though nothing filters.
Please advise.
February 14th, 2008 at 7:54 am
JP,
Can you tell me which version of WordPress you are using?
February 14th, 2008 at 3:10 pm
Currently using, WordPress 2.3.2
May 2nd, 2008 at 11:16 pm
This seems almost like what I’m needing… and maybe it is, but I can’t figure out if it will work or not.
I’m needing something that will do what I’m asking for here
Is that possible?
May 5th, 2008 at 9:57 am
Noel,
That is what the plugin was intended for. You will need to figure out how to change the links to make them point to the dual categories page but this plugin will let you show the posts you want.
May 13th, 2008 at 6:04 pm
Hi Andrew,
first of all thanks for the plugin!
It works fine, but though I have a problem. When I try to combine 2-word-categories and they have one word in common, I do not get the right output.
Example:
categories: ‘category’-one, ‘category’-two, someother
DUALCATEGORIESBASE: filter
http://someurl.com/filter/someother/category-one
In this example I get posts of ‘category-two’ as well. If I combine ’someother’ and ’someother2′ as one-word-categories it works perfectly.
Could you please help? Thanks in advance.
Simon
May 13th, 2008 at 8:55 pm
Simon,
I have figured out what the problem is. I need to make a few code changes to resolve it. I should have another version available today or early tomorrow.
May 14th, 2008 at 7:06 am
I have just uploaded a new version that should work with categories that have spaces now.
May 14th, 2008 at 7:41 am
[...] updated my Fun with Categories plugin this morning. The update is a relatively minor bug fix, but as many of you weren’t [...]
May 14th, 2008 at 9:07 am
That’s what I call support! It is perfect now. Thanks a lot Andrew!
Cheers,
Simon
July 16th, 2008 at 7:57 am
[...] be used to interact with these. These can be searched, sorted or Add a simple plugin, such as my Fun with Categories plugin that allows posts to be filtered by two categories and it is easy to see how an application [...]