4

I am trying to make a taxonomy menu using the Taxonomy Menu module with a custom path for the taxonomy terms. Instead of /taxonomy/term/tid I want /proj/!tid (or ultimately /proj/!term-name but I'll settle for what I can get). I have the taxonomy menu working fine when I leave the "menu path type" setting to default, which leaves it as /taxonomy/term/tid. Whenever I try to use the "vocabulary path" option though, the menu terms all disappear. I've tried to follow the instructions in the documentation here.

I have a view with Taxonomy: Term ID (with depth) and Taxonomy: Term ID depth modifier arguments and a page display with the path set to proj/%. I've tried additionally making a url alias at proj and proj/% but that didn't seem to make any difference. But basically whenever I set the menu path type to "vocabulary path" ("custom path" in the documentation), the menu items all disappear. The terms are still there, and I can navigate to /proj/%, but there are no menu items.

Any help with how to have a custom path for the vocabulary while keeping the menu items would be greatly appreciated.

3 Answers 3

3

If you want to alter taxonomy term paths for taxonomy terms implemented by your module, then you can implement hook_term_path(), which is the hook that allows a module to alter the taxonomy term paths.

The function that returns the taxonomy term paths is the following:

    function taxonomy_term_path($term) {
      $vocabulary = taxonomy_vocabulary_load($term->vid);
      if ($vocabulary->module != 'taxonomy' && $path = module_invoke($vocabulary->module, 'term_path', $term)) {
        return $path;
      }
     return 'taxonomy/term/' . $term->did;
  }

Implementing that hook would also help to modify the path of any vocabularies, if the field $vocabulary->module is changed to the short name of the module you created.

Alternatively, you can write the custom_url_rewrite_outbound() and custom_url_rewrite_inbound() that allows to rewrite the URLs being shown to the "outside" world, and convert a URL into the one used by Drupal.
The example given in the documentation should make clear how to use this functions.

function custom_url_rewrite_inbound(&$result, $path, $path_language) {
  global $user;

  // Change all article/x requests to node/x
  if (preg_match('|^article(/.*)|', $path, $matches)) {
    $result = 'node' . $matches[1];
  }
  // Redirect a path called 'e' to the user's profile edit page.
  if ($path == 'e') {
    $result = 'user/' . $user->uid . '/edit';
  }
}

function custom_url_rewrite_outbound(&$path, &$options, $original_path) {
  global $user;

  // Change all 'node' to 'article'.
  if (preg_match('|^node(/.*)|', $path, $matches)) {
    $path = 'article' . $matches[1];
  }
  // Create a path called 'e' which lands the user on her profile edit page.
  if ($path == 'user/' . $user->uid . '/edit') {
    $path = 'e';
  }
}

In other cases, you can use a module like Pathauto, or Views Term Path Override, which allows to override the taxonomy term paths in views.
Other modules that could be of help are Path redirect, and Taxonomy Redirect; The project page for Views Term Path Override suggests Taxonomy Views Integrator as alternative.

2
  • Views Term Path Override looks promising. Thanks. I'll try that in a bit and see if I have any luck. I'm not sure though if that will live the menu items from Taxonomy Menu intact. Do you know if it would? Or is this for a use-case without Taxonomy Menu?
    – Jay
    Commented Mar 19, 2011 at 18:24
  • 1
    It doesn't seem Views Term Path Override is incompatible with Taxonomy Menu. You could be interested in what reported in Using Term Path Override as a menu item.
    – avpaderno
    Commented Mar 20, 2011 at 22:35
0

Try using Pathauto. I have used it in conjunction with Taxonomy Menu with great results.

2
  • I'm worried about using Pathauto on my site because it's a multilingual site (see: drupal.org/node/269877). Is pathauto required for taxonomy menu custom paths?
    – Jay
    Commented Mar 19, 2011 at 18:15
  • Pathauto plays great with multilingual sites
    – Alex Weber
    Commented Mar 19, 2011 at 18:29
0

You may want to try http://drupal.org/project/tvi I'd have success taking over term pages with that. Especially with attachment displays.

This one claims the same thing: http://drupal.org/project/views_tpo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.