Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top