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:

  1. Install the category module.
  2. Install the pathauto module.
  3. Install the category_pathauto module.
  4. 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].
  5. 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].
  6. Create a category structure, such as that described in the basic hybrid structure tutorial. Your structure should consist of containers, categories, and assigned nodeis.
  7. 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!

Problems

It works like a charm while using [menupath] but with [categoryipath] and [categorypathfirst] it goes all flat like there was no hierarchyi.

I get aliases like:

[categorypathfirst]._0 node/34
[categorypathfirst]._1 node/35

and where i use categorypath:

papper node/44
papper_0 node/46

similar problem

I get the same problem here. I don't know if it's the categoryi_pathauto, pathauto, or my drupal install's problem. I'm using vbDrupal 4.7 alpha 2, so I'm wondering if it's compatibility or the module's problem.

Doesn't seem to be pathauto

Doesn't seem to be pathauto to me since it works great with the [menupath] pattern, but that break compatibilty with my ecommerce store..
And the categories seems to work fine to.

Authors, any suggestions?
Anyone else?

Same for me

I got : [categoryipathfirst]_0 - I got also this kind of url with containerifirst if I remember well...

What if don't assign a category?

If I create a node and don't assign a categoryi, [categorypathfirst] is taken literally by pathauto. I get:

http://www.mysite.com/%5Bcategorypathfirst%5D

What's the solution to this? I'd really like to have categories being optional instead of mandatory.

Thanks for the great module, BTW.

category_pathauto not working

This still seems to be a problem. [menupath] works for categories, but when adding a story or page, no path is created. None of the categoryi_pathauto placeholders seem to do anything. Does anybody have a workaround for this?

I encountered the same

I encountered the same problem. It seemed to work at first and then all the contents lost their aliases.

How does categories integrate with pathauto?

I have Category 5.x-1.1 installed and Category pathauto enabled. I also have Pathauto 5.x-2.0 installed and in most cases pathauto seems to work quite nicely. However, when trying to have paths generated to my categories and containeris I am not able to find the placeholders [container], [categoryipath] and so on in the form of Pathauto.
I've been trying to reverse engineer how these modules work together and it does not make sense to me.

category_pathauto implements a hook called

<?php
 hook_pathauto_node
() 
?>

This hook is, as far as I'm able to tell, NEVER CALLED. In my humble opinion this (or a similar hook) should provide pathauto with the placeholders of the Category module.

Pathauto does call hooks for retrieving placeholders, but this is done throug calling something like hook_pathauto() with the 'settings' parameter - not the 'placeholders' parameter and a node object that hook_pathauto_node() appears to expect.

The options I do have includes using taxonomy pathauto placeholders that are implemented in a taxonomy_pathauto() hook. Using these placeholders I get aliases genereated pointing to real paths (like: 'node/' and 'taxonomy/term/0/feed') that does not work at all.

I have checked Pathauto versions 5.x-1.2 and 5.x-1.1 and they both call hook_pathauto('settings') and not hook_pathauto_node('placeholders', $node).

Can anyone shed some light on this for me?

/Sten

Possible solution

Hi stenjo,

I found exactly the same problem as you, I have submitted a possible fix to this problem as an issue on the categoryi module -- see here http://drupal.org/node/254231.

Does that solve it for you?

tom :)