With the help of Nick Lewis' great tutorial on the correct use of the taxonomy_menu module, I was easily able to build a navigation block that used taxonomy terms.

However, I don't want urls such as www.mydomain.com/taxonomy_menu/5 or www.mydomain.com/taxonomy_menu/5/15, but something like www.mydomain.com/programmes/research, where programmes is the vocab name and research is a term in the vocab.

If I put [vocab]/[cat]/[title] in the Node Path settings of pathauto, that takes care of the node aliases perfectly. However, it leaves the actual taxonomy terms unaliased and I simply don't know what to put in pathauto's Category Path settings.

If I put [vocab]/[cat] in the Category Path settings for that vocab, it generates additional aliases for the taxonomy terms. You can see the problem if you click on the 'Child Care' link (below the node title) on this node page on my test site. The links on the left navigation block are the ones I originally aliased for taxonomy_menu (that is, instead of taxonomy_menu/5/50, I put in the alias communities-of-practice/child care).

I would be very thankful for some assistance.

CommentFileSizeAuthor
#23 taxonomy_menu_0.module6.91 KBLowell
#14 taxonomy_menu.module6.65 KBLowell
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mikeryan’s picture

Project: Pathauto » Taxonomy Menu
Version: 4.6.x-1.x-dev »

You're asking for automatic aliasing of terms to taxonomy_menu paths, correct? That support should come from the taxonomy_menu side - pathauto is designed so that contrib modules like taxonomy_menu can easily hook in their own path generation rules, it's not appropriate for pathauto to build in knowledge of all the various contrib modules out there.

venkat-rk’s picture

Yes, I need the aliases for the taxonomy_menu urls. I will request the taxonomy_menu maintainer, as you suggested.

mikeryan’s picture

You can consider them asked, since I moved this issue to Taxonomy Menu.

It's not that I'm too lazy to add support for other modules (well, not only for that reason:-). As long as I do my best to keep the pathauto API upward-compatible, there will be a lot less version compatibility issues in the long run if client modules maintain their own pathauto support (through whatever changes they make to their functions and tables) than if it's left to me to try to track the changes.

Of course, if the pathauto API is missing the necessary functionality, or seems too complicated, I'll be happy to help other module authors add the support - I welcome the feedback.

saml’s picture

IMHO this functionality is essential for a full-fledged drupal config. Change status to bug report or feature request?
(Thanks for keeping up the good work!)

Success’s picture

Any update to this?

venkat-rk’s picture

I am afraid not. Mikeryan no longer maintains pathauto and it was some kindly developer (kbahey, I think) who upgraded it to 4.7

Category.module does everything (and more) that drupal admins look to do with taxonomy_menu, but that also has a few issues at the moment:(

JoshLangner’s picture

Category module is in bad shape--too bad to be useful anytime soon. It will be far less trouble to get taxonomy_menu working with the pathauto aliases. Can we get someone working on this ASAP?

NicolasH’s picture

Version: » 4.7.x-1.x-dev

Has there been any progress on this? Both modules are very useful, but I couldn't find a way to combine the functionality.

Are there other ways to achieve this (other modules and/or combinations)?

Lowell’s picture

I think I am having the same trouble, and in my case might be close to a solution but need a little help with the taxonomy_menu.module

Using the menu format taxonomy/term/[term number] and then aliasing with a name works for my menus and I would like it work with the breadcrumbs too.
The taxonomy.module writes the breadcrumbs as taxonomy_menu/[category number]/[term number].
I tried a simple hack to write taxonomy/term instead of taxonomy_menu and it almost worked except I lost the parent breadcrumbs and the [term number] was represented by [parent number]/[term number]

Sooo, if this was understandable, you might think that a rewrite to use the taxonomy/term format versus the taxonomy_menu format might be a start to solve the above problems?

Am looking for feedback...

Thanx

TheWhippinpost’s picture

@Lowell etal

You may have seen my hacks (or not). The problem I am seeing - and for which the hacks are tuned - is that taxonomy_menu generates an additional duplicate path alias within the URL_Alias table of the database...

... by that I mean an additional copy of the normal system-designed alias: 'taxonomy/term/#' path

For example (URL_Alias):

Normal alias:

'taxonomy/term/169' - MAPS TO - 'other-hardware/index.htm'

Tax_Menu alias:

'taxonomy_menu/14/169' - MAPS TO - 'other-hardware/index.htm-0'

(Note: The above could equally apply the other way round (which is what we want), ie... the "-0" applied to the normal alias and vice-versa. Entirely depends in which order the aliases are updated by Pathauto)

I'm not sure if this is by-design (as a work-around to something), a bug, or a design change to Pathauto's way of avoiding dupe paths

In your case, try checking the URL_Alias table for your problem paths, then search for each duplicate with the "-0" appended.

If you notice the above pattern (in that order), then delete both their entries from the URL_Alias table.

Now go to: Admin > Settings > Pathauto

... and in: ''Category menu path settings", apply the placeholder pattern to the content-type you are targetting only. IE... no default pattern set, nothing - just a pattern for the content-type.

Enable the bulk update for this menu and apply the update.

Now you can go into: 'Category path settings' and do the same in there, as above.

This will reverse the order aliased paths are duped and breadcrumbs hould appear in-tact - If not then you could look to my hack (link above).

But then, you will probably come up against a feed-path problem... which is where I'm at now!

HTH

Drupal and paths kill me I tells ya, sheesh!

Lowell’s picture

I appreciate the post.. but We must have different issues, my symptoms are not the same.

I like the taxonomy_menu module in that it creates menu items and breadcrumbs accurately. My install is not creating aliases which is ok for now especially since the pathauto does such a nice job of that.

Example: created a "test" term in an existing category

* Created new alias test for taxonomy/term/21
* Created new alias test/feed for taxonomy/term/21/0/feed
* Created new term test.

(it looks like pathauto is responsible for the aliases)

Taxonomy_menu created a menu item with the taxonomy_menu/4/21 path and the breadcrumbs are taxonomy_menu/4 and taxonomy_menu/4/21 respectively. Since the aliases are already done by pathauto, menu and breadcrumb values based on the term format would be perfect.

My complication is that a link or breadcrumb to a taxonomy_menu/#/# breaks the breadcrumb trail whereas taxonomy/term/# does not break

For my site it should work flawlessly for the taxonomy_menu.module to create toxonomy/term/# links and breadcrumbs as long as it doesn't lose parent breadcrumb information.

This is something I will look into myself eventually, taxonomy_menu.module appears to be quite small, (only six functions and less than 200 lines of code?), but I was hoping someone familiar with the logic could provide an effective rewrite.

TheWhippinpost’s picture

Might be a different cause, but the symptom is the same, ie... losing the breadcrumb on taxonomy/term/#.

The reason is paths - You won't get the taxonomy_menu module's features by pointing to a taxonomy/term/# URL because that is the "real" path utilising Drupal's-packaged taxonomy module, not tax_menu.

Tax_menu build's its own paths "over-the-top" of Drupal's paths, stitching together the hierarchy from the vocab, terms/subterms and preceding them with its own moniker: taxonomy_menu/#/#...

Pathauto doesn't overwirte, or delete existing terms; instead, it appends a "-0". So, by creating a term, Pathauto reads the system-designed one, and maps your friendly version to it, within URL_Alias. Should another request be made to create the same term, for another vocab for instance, or in our case (in mine anyway), for taxonomy_menu, it has to create a variation in order to avoid destroying the original term... so now we have 2 different paths, mapping to the same term, but providing 2 different pages, ie... breadcrumbs etc...

I'm stopping there before I tie myself in knots but the substance of my observations are there for you (or anyone) to refer to if your own observations come to a dead-end.

Lowell’s picture

I've applied a little hack to get a result close to what I am looking for. This line of code is inserted in two places in the taxonomy_menu.module (see attachment)

$path = 'taxonomy/term/'. $term->tid;

They are easy to find because they are not indented.
The first instance effectively corrupts the new menu item but I have a workaround that suits my needs at this time.
The second instance effectively sets the breadcrumbs the way I want them but seems to add an extra/redundant breadcrumb for multi-level categories which won't hurt my site either.

These were just shot-in-the-dark hacks that might shed some light on the problem I am actually working through. Any insight into the modules logic will be helpful.

Thanks for your posts about the duplicate aliases, but in this install, taxonomy_menu is not creating any of the aliases, only menu items

These menu items are really weird. I can't edit them and after modifying the module, they have a negative number that is double what it is supposed to be. You'ld have to be there to understand what I mean. But the really cool thing is that when I manually create a menu item with the same name as the taxonomy item and direct it to the corresponding taxonomy/menu/#, it already has an alias created by the pathauto so it works perfectly, and it automatically eliminates the goofy menu item created by the hacked taxonomy_menu_menu function

whoa...way too confusing? hope not

I hope this is getting me close and maybe others can use a bit of this after it is refined. Having functional and consistent breadcrumbs and menus, both automatically generated as well would be a dream come true in Drupal...

Lowell

Lowell’s picture

FileSize
6.65 KB

here is the attachment for the previous post

peterx’s picture

taxonomy_menu.module function taxonomy_menu_menu($may_cache) creates a menu item list containing callbacks to function taxonomy_menu_page() so that taxonomy_menu can update it's location on entry to the next page. I changed taxonomy_menu_menu to create aliases for taxonomy, of the form taxonomy/term/nn. The following code is working on one of my sites.

Taxonomy_menu creates a weird multilevel path because menu.inc builds the menu structure based on the slashes in the path. menu.inc cannot create a structured menu from taxonomy/term/nn so I modified menu.inc. See Allow manual specification of parent. An item's parent is specified by $item['parent'] = 'taxonomy/term/' . $parents[$term->tid];.

Breadcrumbs end up with a useless "taxonomy term" between Home and the next term. Remove the term by editing taxonomy.module, function taxonomy_menu($may_cache), and change $items[] = array('path' => 'taxonomy/term' from 'type' => MENU_CALLBACK to 'type' => 0.

Some of the "read more" links end up pointing to the term instead of the path. I overrode the link in my theme instead of fixing it in the code.

/**
 * Implementation of hook_menu().
 *
 * Most of the heavy lifting of the module is done here.
 */
/* Copyright PeterMoulding.com 2006 12 16. Free for use in Drupal.
1/ Fix formatting.
2/ Change to use URL aliases from taxonomy+pathauto by creating paths
   of the form taxonomy/term/nn and manually specifying the parent of
   each menu item. Requires modification to menu.inc.
*/
function taxonomy_menu_menu($may_cache)
	{
	$items = array();
	if ($may_cache)
		{
		$access = user_access('access content');
		foreach (taxonomy_get_vocabularies() as $vocabulary)
			{
			if (variable_get('taxonomy_menu_show_'. $vocabulary->vid, 1))
				{
				$parents = array();
				$tree = taxonomy_get_tree($vocabulary->vid);
				foreach ($tree as $term)
					{
					$parent = reset($term->parents);
					if($parent > 0)
						{
						$parents[$term->tid] = reset($term->parents);
						}
					$item = array();
					$item['path'] = 'taxonomy/term/' . $term->tid;
					$item['title'] = t($term->name);
					$item['weight'] = $term->weight;
					if(isset($parents[$term->tid]))
						{
						$item['parent'] = 'taxonomy/term/' . $parents[$term->tid];
						}
					
					if(!$use_vocabulary_name and $term->depth > 0)
						{
						$item['callback'] = 'taxonomy_menu_page';
						$item['access'] = $access;
						}
					$items[] = $item;
					}
				}
			}
		}
	return $items;
	}
Lowell’s picture

Greatly appreciated! :-)

I applied these three changes to a new site and they managed the menu items and their aliases very well. In addition I hope this will give me more insight into the inner workings of drupal and the modules.

The Breadcrumbs, however, still link to taxonomy_menu/nn/nn addresses. It appears as thought this final issue will make building heirarchal menu sites a breeze.

Thanks again for the great info.

Lowell

Lowell’s picture

Finished!!!

I would call this a completed workaround. Will do more testing, for example I haven't tried nested categories yet.

The icing on my cake was applied with this line of code right near the end of the taxonomy_menu.module as shown here

$path = 'taxonomy/term/'. $term->tid;


function taxonomy_menu_nodeapi(&$node, $op, $a3, $a4) {
  switch ($op) {
    case 'view':
      if ($a4 == TRUE) {
        // The node is being displayed on its own page.
        foreach (taxonomy_get_vocabularies() as $vocabulary) {
          if (variable_get('taxonomy_menu_show_'. $vocabulary->vid, 1)) {
            $path = 'taxonomy_menu/' . $vocabulary->vid;

            $tree = taxonomy_get_tree($vocabulary->vid);
            $old_depth = -1;
            $old_path = $path;

            foreach ($tree as $term) {
              if ($term->depth <= $old_depth) {
                $slashes_to_remove = $old_depth - $term->depth + 1;
                for ($i = 0; $i < $slashes_to_remove; $i++) {
                  $old_path = substr($old_path, 0, strrpos($old_path, "/"));
                }
              }
              $path = $old_path .'/'. $term->tid;
              $old_depth = $term->depth;
              $old_path = $path;
$path = 'taxonomy/term/'. $term->tid;
              if (in_array($term->tid, array_keys(taxonomy_node_get_terms($node->nid)))) {
                menu_set_location(array(array('path' => $path, 'title' => t($term->name)), array('path' => 'node/'. $node->nid, 'title' => $node->title)));
                // Quit after the first match.
                return;
              }
            }
          }
        }
      }
      break;
  }
}

Lowell’s picture

Wait Wait Wait
I've already found a bug... Try editing the menu items automatically created that match the categories and you'll see what I mean.

The item number is represented by an unusually large negative number. I am guessing it is double what it's supposed to be.
Maybe another little fix for this part and we'll really be all set.

Thanks in advance to the next helpful bystander :-)

TheWhippinpost’s picture

Whoa!

... this has exploded since I last looked!

Lowell:
Have you seen these threads?
http://drupal.org/node/41476#comment-181146
http://drupal.org/node/103539

And peterx:
Which of these latest code-dumps matter?!

Lowell’s picture

I want to say thanks again to peterx for all your help. It looks like you've been at this one for a while.

To whippinpost (you don't mind that I call you this, do you?), It looks like peterx has combined all the steps so far and then did some cleanup at the end. I found little to clean in my install as it is a new site, actually testing this on three different sites.

Did a little more testing. First of all, I removed all my modifications and went strictly with peters.
I still have a menu editing problem when I create a new category term with <root> as the parent. But when I nested the new category term it worked perfectly.

I would like to know if this is only my install (but it does it on all my test sites)

Following is the description of the trouble when a new category term is created with <root> or nothing as parent:

1. the menu item is created in the Navigation menu and has a working alias
2. I cannot edit the menu item, cannot delete it, disable it or anything to it
3. menu item does not appear in the drupal_menu table
4. menu item number with path (as shown in the url after clicking on it) is admin/menu/item/edit/-401
5. the largest value for drupal_menu.mid is 229 so the above path should be admin/menu/item/edit/230
6. subsequent item numbers are incremented as -402, -403, etc.
7. as a workaround I create another menu item referencing the taxonomy/menu/## and it effectively replaces and erases the -401, etc, menu items.

I haven't found where these -401, etc, values are being stored but will keep looking

Again, somebody please tell me if it's just me.

Lowell

Lowell’s picture

One more note...

I had to re-insert this line of code (I call it a hack because I don't really understand the logic) to change the breadcrumbs to a taxonomy/term/# format. Retested the above scenarious and they are the same as before.

$path = 'taxonomy/term/'. $term->tid;
into this function
taxonomy_menu_nodeapi(&$node, $op, $a3, $a4)

Good luck peterx if you decide to solve the menu item issue. I have decided to nest everything so only the top level category items need manually entered and then disabled (they are a placeholder only). Once this is done, I can automatically create menu items with working breadcrumb links by simply adding taxonomy terms (aka category terms).

Thanks again for your valuable programming work.

Lowell’s picture

as nice as this sounds, I tried a third level (nested twice) taxonomy term and sure enough, the only thing that broke was the breadcrumb trail, obviously the result of my 'simple' hack that doesn't take into consideration more than one iteration.

still have my fingers crossed that this will be an easy one for you peterx

Lowell’s picture

FileSize
6.91 KB

BINGO

I can hardly beleive it! Tested it every way I can and it works perfectly. Here is what I did to the taxonomy_menu.module (knew I was close)

changed this line right near the end of taxonomy_menu.module in the function taxonomy_menu_nodeapi(&$node, $op, $a3, $a4)

from this $path = $old_path .'/'. $term->tid;

to this $path = 'taxonomy/term/'. $term->tid;

of course leave the rest of the function the way it originally came, this means that my previous hack is no good, here is the whole function as I am now using it. (attached is the whole taxonomy_menu.module including peterx modifications)

Bevan’s picture

did this ever get commited to any CVS branch?

It seems not. Who's maintaining this module?

Anyone?

Bevan’s picture

I'm having a go at porting this to drupal 5: http://drupal.org/node/121513

Summit’s picture

Hi,

I tried this patch on drupal 4.7, but it is not working...
My main taxonomy category is not shown in the menu, but all the underneath categories are shown on top level..this is off course not what I want.
Can somebody please get into this?

greetings,
Martijn

executex’s picture

I'm a PHP developer for many years, and I believe Taxonomy_menu is the #1 most important module in Drupal. I don't know what sorta CMS doesn't have Taxonomy_menu built-in.... It really bottles my mind, how careless Drupal developers can be when they made the CMS without a proper way to categorize taxonomy.

It's the #1 reason why some developers REFUSE to use Drupal. Every one of them I argued ends up with "well I didn't know there was a taxonomy menu module".

However, although as good as taxonomy_menu is, I am shocked at the amount of carelessness the developers of taxonomy_menu had when developing their module. What kind of developer uses horrible URLs like "taxonomy_menu/1/3" instead of simply using taxonomy's urls like "taxonomy/4/56" ... Then when we path-auto it, all taxonomy menu and taxonomy should point to like "vocab/term/article" or "vocab/term"... I don't see why any developer would not have considered this the #1 priority for this module, unless they knew absolutely nothing about SEO, or that it was so incredibly difficult that they didn't wanna do it.

I am this close to getting my development team to sort through this taxonomy_menu module and rebuild our own.

I think if we develop our own, it will have to have DHTML to be able to hide/show the list of terms under each vocab in the navigation, and proper URL aliasing with the use of path-auto. I seriously cannot understand why it is so difficult, bear in mind, I have not opened up the taxonomy_menu and looked inside yet, so I am jumping to conclusions, but if taxonomy is developed similar to any other CMS, then it should be like 40 lines of code at most.

Please tell me why no one has found a proper solution or udpated Taxonomy_menu so that it's up to date with all other websites in the world.

Bevan’s picture

Please find another place to vent your frustrations. I don't think many if any other drupal.org users will appreciate it.

I'm sure there are good reasons as to why things have been done the way they've been done. I also haven't looked much into the code of taxonomy menu module, but my understanding of the reasons are:

Modules use system paths (otherwise known as drupal paths) which allow for code-efficiency. Most contrib modules don't choose their drupal paths based on SEO motivations, they leave SEO of paths to be abstracted into modules like path and pathauto. It's good practice for modules to restrict their module's paths to a namespace, to avoid conflicting paths and other reasons. Taxonomy menu module requires several slashes and numbers (34/65/8/9) because of the way the menu module was designed, which could be seen as a feature or a limitation. There are some changes (I think) in drupal 6 that will allow for shorter simpler drupal paths in taxonomy menu module (and other implementations of hook_menu of course).

See my posts in this thread that explains some of this in slightly more detail: http://drupal.org/node/121513

This would have been best as a separate issue, as it's quite unrelated to this thread. Also the issues about taxonomy core module would need to be put in the taxonomy module's issue queue to be addressed. Although I think you'll also find that there are good reasons as to why it works the way it does. Having said that, taxonomy module has been rewritten in drupal 6, I believe.

About DHTML menus, I suggest you look at DHTML_menu module, which can be used in conjunction with taxonomy_menu module to do what I understand you are trying to achieve. Also, I'm fairly sure you can achieve what you are trying to achieve with taxonomy_menu module, path module, and some custom code in a custom module, simply by setting path aliases on hook_init and/or taxonomy hooks.

Yes it would be nice if we could do this with pathauto, and I think this is also possible, with a bit more care and code. Wouldn't it be great to get a patch into taxonomy_menu module that does this?

Summit’s picture

+1 for enhancing taxonomy_menu.
I work with a combination of taxonomy_menu and taxonomy_context and a custom-block, but getting above functionalitiy in one in a taxonomy_menu module would be great!
Please keep me posted about your progress, and please stay possitive, we all try to build the greatest CMS on earth!!

greetings,
Martijn

executex’s picture

Yeah I do believe I'm going to get my team to construct a much better taxonomy Menu system. It's not even that difficult, as we have become use to making custom modules for our site www.igzones.com

Summit’s picture

Hi,

It is allways good to give the custom modules back to the community, so other people will look into it and improve your way of thinking I think.
I am looking forward to the module!
greetings,
Martijn

gagarine’s picture

Yeah and it will be great if you can choice the parent (primary links, other sub menu of Navigation and so) for each menu created with taxonomy_menu

ZaphMann’s picture

Version: 4.7.x-1.x-dev » 5.x-1.x-dev
Component: Documentation » Code

Wow, reading this thread and http://drupal.org/node/143994 confirmed to me that others have had my problem but left me not quite understanding what to do next.

I am a new and keen convert to Drupal, using core plus steadily adding modules. I have my menus working beautifully using both taxonomy_menu and dhtml_menu (& simplemenu). SEO optimization is important for a world-wide community to find the site pages so I have had pathauto enabled from the start. However, I have precisely the problem of the first post on this thread (from last year):

I don't want urls such as www.mydomain.com/taxonomy_menu/5 or www.mydomain.com/taxonomy_menu/5/15, but something like www.mydomain.com/programmes/research, where programmes is the vocab name and research is a term in the vocab.

My questions:

1. I want to avoid hacks wherever possible - Can I then solve the problem as per Martijnhaan on July 7, 2007 "for enhancing taxonomy_menu. I work with a combination of taxonomy_menu and taxonomy_context..."?

2. The other thread I mentioned also addresses SEO and pathauto, and XML sitemap and http://drupal.org/project/globalredirect.

  • 2a: Once I fix the URL name problem, will I need to produce a sitemap to get search engine acknowledgement?
  • 2b: I don't fully understand how a sitemap works in conjunction with the outside world - do I have to submit a sitemap to search engines?
  • I hope this is the right place to ask, I don't want to just load up modules and confuse the issue.
    Many thanks for any enlightenment.
    Zaph
    www.morethanoil.com

    emilyf’s picture

    I also need taxonomy menu to use pathauto. I tried this hack to the TM module, but while it is close to what I need, it is too buggy. It puts everything in one huge menu, and there is no ability to edit because it somehow creates links to menu items with numbers like -401, -500, etc. It's completely random.

    Any plans to actually put this into the module for 4.7 and 5? It seems crazy that it doesn't exist and this thread is almost a year old!

    druvision’s picture

    Status: Active » Needs work

    As a temporary solution, I've written a module which uses custom_url_rewrite to change all taxonomy_menu URLs to the correct taxonomy/term/... form, and works with pathauto URLs.

    This works great on the top nice_menus on my site, http://levavie.com.
    For more info, see here: http://drupal.org/node/192493#comment-633741

    Amnon
    -
    Professional: Drupal Israel | Drupal Development & Consulting | Effective Hosting Strategies | בניית אתרים
    Personal: Hitech Dolphin: Regain Simple Joy :)

    Bevan’s picture

    Ah, very nice!

    mhuebl’s picture

    I don't know if it was already mentioned. But this snippet [1] gives you fully support of pathauto. I didn't test it very much, but it seems to work well at my dev-version.

    [1] http://drupal.org/node/41476#comment-276697

    soundsational’s picture

    I had to manually add in the 'URL aliases'. For Example if your term is 'open source' and uses:

    taxonomy/term/2 but you want /category/open-source

    Click on add alias, for the existing path type in taxonomy/term/2 and for the alternative path type in category/open-source

    This should work. If it doesn't, first try and delete all terms and vocab for the aliases and then manually add them in as shown above.

    There is one problem, you cannot have the same aliases, so either you apply it to taxonomy menu or leave as for the tags.

    This was tested on Drupal 5

    thanks,

    Murz’s picture

    I add some support for pathauto module in my patch Patch for remove vid or module page from url (with pathauto support), you can try to use it.

    arlinsandbulte’s picture

    Status: Needs work » Closed (won't fix)

    This issue is old and out dated....