The Taxonomy Menu allows you listing all taxonomies in a menu. You can either link the taxonomy by term id or term name. I have Pathauto installed such that each term is linked to a URL alias.
Unfortunately, you cannot replace the special characters in the term name. The following is a list of terms and their corresponding links.
- Apple & Pear ﹣ products/apple-%26-pear
- l’orange – products/l’orange
- Apple (Green) – products/apple-(green)
- Lemon/Grapefruit – products/lemon/grapefruit
The above links are all not valid links. The correct URL alias created by Pathauto should be.
- Apple & Pear ﹣ products/apple-pear
- l’orange – products/lorange
- Apple (Green) – products/apple-green
- Lemon/Grapefruit – products/lemongrapefruit
You can either change the Pathauto setting but this does not work anyway for a term name with ‘/’. An alternative is to replace the special characters when generating the menu link.
Edit the template.php in your theme folder and add the following theme function.
/** * This function replace the special characters in the taxonomy when generating the taxonomy menu with term name. */ // Remember renaming the function to <theme_name>_menu_item_link function phptemplate_menu_item_link($link) { if (empty($link['localized_options'])) { $link['localized_options'] = array(); } // replace special characters $href = str_replace('&-' ,'', $link['href']); $href = str_replace('(' ,'', $href); $href = str_replace(')' ,'', $href); $href = str_replace("'" ,'', $href); // replace the 2nd occurrence of '/' $href_head = substr($href, 0, strpos($href, '/')+1); $href_tail = substr($href, strpos($href, '/')+1); $href_tail = str_replace('/' ,'', $href_tail); $href = $href_head.$href_tail; return l($link['title'], $href, $link['localized_options']); }
This should solve the problem.
Done =)
Reference: Drupal APi – theme_menu_item_link
Filed under: CMS Tagged: Drupal, Drupal Development, Pathauto, Taxonomy, Taxonomy Menu, URL Alias
