Using pathauto with category
Now that the new categoryi_pathauto module is available in the category package, it is possible to automatically generate URL aliases that perfectly match your site's category structure!
Previously, getting such URLs with the pathauto module was something of an art form. A number of solutions existed, but none of them were perfect. The best option (in my experience) was to use pathauto's [menupath] placeholder to generate URLs based on your menu structure. If you're using category_menu, this is actually just as good a solution as is using native category module placeholders. However, the rewards of this placeholder are dependent on category_menu being used throughout your site, which not everyone is able or willing to do. Other options, such as using the [catpath] and [bookpath] placeholders (for the taxonomy and book modules, respectively), were less than optimal.
The category_pathauto module provides five new pathauto placeholders, that you can use as node path settings on your site's admin -> settings -> pathauto page. If you'd like to know the details of these placeholders, have a look at the descriptions on this page. For now, we're going to be looking at the [categorypath] and [categorypathfirst] placeholders.
Here's how you can get started using pathauto with category:
- Install the category module.
- Install the pathauto module.
- Install the category_pathauto module.
- On your site's admin -> settings -> pathauto page, set the placeholder for all category and containeri node types (this is usually just the types category and container) to
[categorypath]. - Also on this page, set the placeholder for all node types that can be assigned categories (such as story, and perhaps some of your CCK node types) to
[categorypathfirst]. - Create a category structure, such as that described in the basic hybrid structure tutorial. Your structure should consist of containers, categories, and assigned nodeis.
- Observe the magic - all of your nodes should have now been given automatically generated URL aliases!
The [categorypath] placeholder works very similarly to the book module's [bookpath] placeholder; and the [categorypathfirst] placeholder works like a combination of the [bookpath] placeholder, and the taxonomy module's [catpath] placeholder. However, unlike their predecessors, these placeholders are designed to be distant-parenti aware, and to exclude hidden containeris from their URL alias generation. So essentially, they should perfectly match your breadcrumbs, your menu items, and your navigation links.
Happy aliasing!