Drupal Navigation Reloaded: Displaying Taxonomy and User Menus as Primary and Secondary links.

07.04.2005

UPDATE: I've writing a multipart tutorial on how this was done, follow it in order:

I've put together an example theme which impliments the top navigation menu that you see in this site. I'm very strapped for time at the moment, so I hope you'll forgive the lack of detailed instructions.

However, if you have any experience with creating new drupal themes, then you should have a very easy time figuring out how it works. It doesn't require any new database tables, or modules. All that is required is php-template. For the lovely categorization that you see in this site, you'll also need the taxonomy menu module, though.

There are four critical changes in the code that are worth highlighting

  • page.tpl.php (lines 8-11): Box Grey's default inclusion of stylesheets has been overrided. Now the path is static, and currently set to "themes/boxgreynav/style.php".
  • page.tpl.php (lines 33-43): The include for primary and secondary links was deleted and replaced with a function that calls the user menus [theme_menu_tree($pid)].
  • Box Grey's style.css was converted to style.php to allow inclusion of menu.php
  • The dense CSS coding in the file menu.php is the "magic" that makes this work. The complexity of it made it difficult for even me to switch colors for backgrounds and links. Thus, I've converted the CSS file into a php file. See the file for notes on how that works

That's enough for now, let me know if this works, fails, or makes you want to set buildings on fire.

Comments

me again

Sorry for bothering you, I'm a dumbass, but now have seen that I have to look in my tables for the correct pid. Now it works, so you don't have to answer me. Thanks anyway!

Very impressive, but...

Hi I am an absolute drupal newbee, and so very glad for your entertaining guide for the horizontal menu. I think I have understood the thing as you described it, but what I don't understand: I want exactly what you did on this site here, which means: Take the taxonomy menu as horizontal menu. If I take your box_grey-example above (boxgreynav) the "magic function" is theme_menu_tree($pid) and as standard the number 1 is given for $pid ->it's the standard block on the left side and has the installed taxonomy menu within. For self defined menus then other numbers will be set (as you described it in your first tutorial). But which function I have to call if I ONLY want to have my taxonomy menu (with urls taxonomy_menu/termnumber) - as you did here. Sorry, I have no idea or have overlooked something in your examples. Thanks for any hint.

Great Question Roland, what

Great Question Roland, what you need to do is download and install the taxonomy_menu module. From there, what you do is create a new menu in your admin/menu section, and move the your taxonomy vocab(s) to the new menu. From there, you simply enter your menu's ID number into the your special display menu PHP function, and abbra-kadbra (I think that's how you spell it), you have your menu only for taxonomy items. Let me know if that didn't make sense, I'm afraid I'm completely exhausted from a long day doing an Americorps VISTA orientation... oye.. long year head.

Thanks!

That was exactly what I needed. Now it works and it works great.

brilliant - Thanks - 1 suggestion

Absolutely brilliant, your Nav bar is. Im new to drupal and wasnt keen on the current options, I was so fortunate to come across your nav theme. Its great. 1 suggestion for further improvement would be that when the user hovers over an alternative menu item, the child menu shows, that way a person can quickly view alternative paths rather than having to click each item just to see the path which may not be what he wanted. Anyway a minor point compared to the relative advance your nav theme brings drupal. Way to go Nick

Thanks for the suggestion

Thanks for the suggestion Mark. Having the second hierarchy of links display when the cursor is definately something I'm interested in building. However, that's going to require more significant changes to the drupal core. One thing I'm experimenting with is using ajax to preview related content. I'm glad you found some use for the theme. Feel free to add anymore suggestions if you get an inkling.

tagsonomy browsing

Just continuing.. what I was thinking was you hit the tags button and then the full list of tags apperas.. maybe very big ..nevermind... u hit a tag from the list and related tags drop down...hitting one of these would then drop down an INTERSECTION (like hitting + on delicious) so you only get those results that are in both tags in the drop down menu from that, and so on. so its easy to zoom in on intersections of tags.. does that make sens. I know theres tools to do this, but really by putting this on the tag bar its stating to people that tags are more than just a neat tool they are an alternative way of completely navigating your data. Then of course theres other ideas of faceted search.. maybe can explore tags by user, date, etc...

Interesting... I'll look

Interesting... I'll look into that. I'm very open to new navigation and organization schemes. The internet is a terribily new beast, so the last thing we need are dogmas before we even understand the medium.

civicspace theme

Hi Nick, OK, for something fairly wild ... you mention an ajax preview.. also somewhere else u talk about an ajax delicious tool for browsing tags.. how about combining thoughts and having drupal / delicious tags accessible as part of your nav bar, or is that something too wild :-) If was possible would make your nav bar a very hot property, and may draw more people to drupal just for that (im hoping :-) ) but certainly such a nav bar generating on the fly tag categories for exploring the site would be amazing... would be a totally wonderful way of exploring a site. I loved using your nav bar.. unfortunately for several reasons ive adopted a civicspace them instead of boxgrey nav (which I had asssitance with).. which has given me terrible withdrawal symptoms (for the nav bar - not my old theme) . However Im really not a programmer and civic space new theme seems daunting to incorporate the nav bar in. Is it something thats easily tweakable or not?

Well, if you're not a

Well, if you're not a programmer, and have no understanding of PHP or CSS, than its probably going to be something of a daring adventure into a new unknown world where good men die like dogs for no good reason. However, you have to start somewhere, and for the most part I'm willing to help people who are having problems so long as the describe their problem here, so that my answer can benifit anyone else who might come along.

 As for the AJAX navigation... there are problems with browser support so it would probably be a  bad choice for a global navigation scheme. In addition, I worry that overuse of AJAX might messup a site's google results. I'll have to do more research into that. However, I am experiementing with the integration of AJAX with books. The trouble is, I have no idea what I'm doing so the results of my experiments thus far have been a blank page of white... AJAX style.

As for the navbar in the civicspace theme, I'm unsure of how the theme was coded, so there might be unforseen problems. I am working on a more scalable, and visually pleasing version of the navbar along with some professional work that has me completely booked at the moment. I'll be sure to release the code.   

managed your navbar for the civicspace theme - just

Hi Nick, I just wanted to let you know, I saw your tutorial on the nav bar stuff, and it was a great help. I think thats certainly something really useful that should be made very visible in the Drupal community. Anyway the short of it is that Ive managed to get your navbar running on my civicspace theme, which makes me really happy. Though I nearly did die like a dog (as you put it :-)... Its not very pretty, thats because Im still pretty much in the dark on css (though php seems straight forward now), and getting colors right can be quite awkward (also Im no web designer anyhow). But at least its functional, and makes my site better for it. It turns outits not that its not much harder to do in civicspace theme than any other really, just that from a quick glance the civicspace theme seems a whole extra level complex, but essentially its not. What caused me more difficulty was incorporating an extra tweak that I needed. That is to get two different nav menus showing depending on whether people were logged in or not (i remember another comment here somewhere on that. Well it helped me to switch the nav menu based on logged in or not (was a snippet of code u showed, but instead of switching themes as u did, I switched the nav menu showing... which is really cool and really useful... maybe u should even consider it (that would really make me feel good :-) If you want to have a look at what i did for civicspace and switching nav menus.. let me know and Ill pass u the code over... Im sure youd be able to make a much cleaner job of it and maybe might then be worth sharing for others also.) By the way your last tutorial wasnt posted yet (dont worry u must be really stretched as it is, just to let you know that the code I based mine on in the end reverted to an earlier code snippet you gave for the boxgrey nanvbar, as I just couldnt tweak the latest one to work in the end, but the earlier code worked well. ps.. I feel my online persona is getting quite fragmented with all these comment trails dispersed around :-) there was another comment from u I recall which I just couldnt track down. I think u mentioned connecting. If so please feel free to contact me anytime Nick, I think we share a lot in common, and would love to get more aquainted. All the best, mark the tweaked switching code for nav menus (as Im currently using at http://www.stratagility.com ) is pasted here <?php/*** The following simple snippet* displays different menus to anonymous/logged in users.*/global $user;/** * This presents Stratagility business site menu * for logged out/anonymous users*/if ($user->uid) {    $UserMenu = theme_menu_tree(114);}/** * This presents the community site menu for loggedin users*/if (!$user->uid) {    $UserMenu = theme_menu_tree(105);} print $UserMenu;?>

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options