Single Category Permalink

Author:Scott Reilly
Version:1.0
Last update:11 April 2008
Compatibility:WP 1.5+, 2.0+, 2.2+, 2.3+ and 2.5+
Comments:go here
Download:[ zip ]
Description:

Modify the %category% permalink structure tag to generate a category-based permalink structure that only displays the lowest category in a hierarchy, as opposed to the entire hierarchy of categories.

Extended Description

By default, WordPress replaces the %category% permalink tag in a custom permalink structure with the entire hierarchy of categories for the post’s first matching category. For example, assuming your site has a hierarchical category structure like so:


Applications
  |_ Desktop
  |_ Web
    |_ Wordpress

By default, if you have a permalink structure defined as %category%/%year%/%monthnum%/%day%/%postname%, your post titled “Best Plugins” assigned to the “WordPress” category would have a permalink of:

http://www.yourblog.com/applications/web/wordpress/2008/01/15/best-plugins

If you activate the Single Category Permalink plugin, this would be the permalink generated for the post (and recognized by the blog):

http://www.yourblog.com/wordpress/2008/01/15/best-plugins

In order for a category to be used as part of a post’s permalink structure, %category% must be explicitly defined in the Options → Permalinks (or in WP 2.5: Settings → Permalinks) admin page as part of a custom structure, i.e. /%category%/%postname%.

For category links, %category% is implied to follow the value set as the “Category base” (or the default category base if none is specified).


Installation

  1. Download the file single-category-permalink.zip and unzip it into your wp-content/plugins/ directory.
  2. Activate the plugin through the ‘Plugins’ admin menu in WordPress.
  3. Use %category% as a permalink tag in the ‘Options’ → ‘Permalinks’ (or in WP 2.5: ‘Settings’ → ‘Permalinks’) admin options page when defining a custom permalink structure

Examples

Assuming a category hierarchy of Vehicles -> Cars -> Ford, and a custom permalink structure defined as /%category%/%year%/%postname%, without this plugin being active the permalink for a post titled “Taurus” assigned to the “Ford” category would be:
http://example.com/vehicles/cars/ford/2008/taurus/

However, if this plugin were active, that link would instead be:
http://example.com/ford/2008/taurus/


Release Log


Copyright & Disclaimer

Copyright © 2007-2008 by Scott Reilly (aka coffee2code)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


Acknowledgements

Thanks to all those who have contributed feedback and support!