An (Almost) Perfect Taxonomy Menu

I'm down to the last item on my to-do list for this round of website improvements: come up with a better taxonomy, and a sidebar menu to navigate it. Coming up with the taxonomy was easy enough (I'm lying), the menu not so much.


The beginnings of my new taxonomy menu.

In theory, it seemed easy enough: create the taxonomy, install Taxonomy Menu, and hey presto! And it almost was that easy, except...

Taxonomy Menu doesn't display the category description at the top of the page, the way the default taxonomy listings do. I intend to put real content in the descriptions, so that's something I would need to change. And it doesn't do breadcrumbs: if you navigate to a child term the breadcrumb will still say "Home", the parent terms will not be listed. Okay, so neither of these things are showstoppers, and I could live without them...but why?

I tried using Views, thinking I could make a few tweaks to the default taxonomy_term view. This might be the right long-term solution, but I ran out of time before I was able to figure out how to get the description at the top of the page. A custom template maybe? Anyway, another time.

Back to basics: I made a new menu mirroring my taxonomy and put that in a block. Now I get the breadcrumb and taxonomy description. Sweet. I'll have to manually keep the menu in sync with the taxonomy, but I can live with that as my vocabulary will be small. But (it couldn't be that easy) when I click on Software Development it tells me that there is no content to display, even though I've got a bunch of nodes filed under Drupal, a child term.

The Drupal developers anticipated this, and allow for a depth argument on the taxonomy term URIs. Instead of taxonomy/term/123 use taxonomy/term/123/all. This does in fact show all of the child nodes (yeah!) but now when I click on the parent term in the menu block, it doesn't expand to show the child terms (boo!). Drupal giveth, and Drupal taketh away. And no, it doesn't make any sense to me, either.

That leaves Google, and Google has an answer, but it's a bad answer. A terrible, awful, no good answer. All you have to do is open modules/taxonomy.pages.inc and change this line:

function taxonomy_term_page($str_tids = '', $depth = 0, $op = 'page') {

...to this:

function taxonomy_term_page($str_tids = '', $depth = 'all', $op = 'page') {

30 seconds and you're done; magic ponies for everyone. Ah, but now you've gone and done it: you've changed core code, which means you'll have to redo this change every time a new version of Drupal is released. If you forget, your site will break and everyone will laugh at you. And if Dries ever finds out...

Here are my references. If you know of a better way, could you please throw me a clue? If I do find a more elegant (or at least less awful) solution, I'll be sure to update this page. But for now, it's time for a new version of Premake.

Did you enjoy this article?

Help me write more like it. »