Ferodynamics Network

popular: profile privacy, mobile privacy

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 1.1 – December 2008

Tested against 2.7 beta 3, extra admin functions added.

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:

[php]
is_dual_categories()

This returns true or false to determine if the posts are being filtered by two categories.

Example:

[php]
if ( is_dual_categories() )
{
echo 'Now filtering by dual categories';
}

Include Tags

To compliment the existing functionality the following have been added

[php]
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:

[php]dual_cat_titles(1)

Between:

If showing both categories choose the text to go between them (including spaces):

[php]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:

[php] from

The page displays: Photographs from India

Dual Categories Base

In WordPress 2.7 you can change the URL base used for dual categories from the permalink settings page. By default dual categories permalinks will be /categories/cat1/cat2/ if you enter a word in the dual categories base field you can change it /anything/cat1/cat2/.

dual-cat-base

Download

Download the plugin from WordPress Extend