By crbassett on
Hello -
More and more sites are doing a header navigation structure like the one on this website, for example: http://thethemefoundry.com/wordpress/
I'm wondering if there is an easy way to accomplish something like this in Drupal by showing the primarily link and then its description underneath it. I'm sure it involves some php in the template file, and that's why I'm posting...does anyone have a snippet that would work for this or does anyone want to point me in the right direction... I did find this forum topic: http://drupal.org/node/343440. However, I'm unsure of trying it since the date on the topic is so old. Any help could be appreciated. Thanks so much.
Comments
Try this one out
Put this in your theme's template.php file:
It is a bit confusing that the
$link['title']is the link's text and the$link['options']['attributes']['title']is the description, since they're both named "title" in the end, but that's Drupal for ya!Presumably you could put anything you want in
$link['title']because it's really just the link text. So, if you want the description to also be a part of the link itself, you could just add it to$link['title']Thank you for offering your
Thank you for offering your help. I'll confess I'm not versed in PHP, beyond hacking here and there in snippets and in content templates (contemplate module), so, if you're willing to continue helping me, I'd appreciate it.
I'm using Zen as my theme (actually a sub-theme) called "stephen", so, first of all, I assume (if I remember correctly) I should change the word phptemplate to the name of the theme, so, "stephen_phptemplate_menu_item_link". (I actually tried it both ways, and it didn't work for me either way...
The page.tpl.php file in Zen shows this for printing the primary links:
Do I need to change that declaration in the page.tpl.php file?
Thanks for your patience. I'll hopefully get this working.
Sorry it took so long
Sorry it took so long to get back to you on this!
I just realized that the method I showed you wasn't necessarily the right way to do this. I used an example from an existing site that I had but it only worked in that case because I was using it for a different use case.
Anyway, the theme system basically gives you a way to override functions (defined in modules) that produce the output of html on your site. All you need to do to override one is find the original, copy it to your template.php file, and change it from theme_function_name to yourthemename_function_name. Theme functions are invoked within drupal using the function theme() (like in your example you posted
theme(array('links__system_main_menu', 'links'), $primary_links..... For example you would take the function theme_links, and rename it to stephen_links. Then you would call the function using theme('links') somewhere in your template file.(Sorry, if my use of phptemplate before was confusing, btw. It should work, but you should read more about the theming system to see why =) )
Okay, so, having said all that, Let's look at the snippet from your template file
In this case the function theme() is being passed a few different function options. It will first look for theme_links__system_main_menu() but if it doesn't exist, it will fallback to theme_links. Let's use the first one:
All I've done here is copy the function theme_links, and renamed it to match the theme() call in your template file.
Also, as a side note, the output from my example isn't the best. It will require further theming using css to make sure it displays the way you want. You can also add some extra html in the output as well if you need to.
Anyway, sorry if this explanation is tough to follow, I'm in a bit of a rush and typed it out quickly. =P Feel free to ask more questions if you need to! Also check this out http://drupal.org/node/341628