ChristieMADE.com
  • Home
  • Portfolio
  • Blog
  • Contact
  • Menu Menu

Archive for month: April, 2009

Drupal 6 Submenus Using Primary Links

by Christie
April 1, 2009

I needed a way to display submenus on pages on a website built in Drupal 6. The menu system itself, built with Drupal Menu’s primary links, was three levels deep. So, a small snippet of the menu as an example would be:

About Us >
    Directors
    History
    Mission
Services >
    Pricing
    Administration
        Trusts
        Estates
    Special Needs

If someone is on the “History” page, I want a sub menu to appear on the left with all the other links that appear under “About”. Drupal has a module called Submenu Tree which comes with hardly any instructions, and didn’t seem to work. So after much digging around, I found a quick and simple solution using some Drupal functions and the template.php file.

In my theme’s template.php file I created a new function called Submenu() that looks like this:

<?php

function Submenu() {

$menu_theme = menu_navigation_links(“primary-links”,2);
$menu .= “<ul>”;

foreach ($menu_theme as $value) {
  $menu .= “<li>”;
  $menu .= l($value[‘title’],$value[‘href’]);
  $menu .= “</li>”;
}

$menu .= “</ul>”;
return $menu;
}

Then, in your page.tpl.php file, whereever you want the menus to appear, just do a print(Submenu()); and voi-la!!

The code explained:

$menu_theme = menu_navigation_links(“primary-links”,2);

This is a drupal function that will return an array of all the links relative to the current menu, the second argument, the ‘2’, says I want to see all the links for the 3rd level. If I was on the “Trusts” page, this would return an array with “Trusts” and “Estate” link information.

$menu .= l($value[‘title’],$value[‘href’]);

This is another Drupal function that creates an automatic link based off link text and a path URL. Both of these are made available to us from the array we got in $menu_theme.

0 Comments
drupal, problems & solutions
drupal, links, submenu

Categories

  • great links
  • how-tos
  • problems & solutions
    • back-end
    • drupal
    • jquery
    • wordpress
  • recommendations

Tags

ajax animation apache audio captcha colorbox CSS css3 domain management drupal Elementor Enfold godaddy google hosting Hosting Configuration hosting management HTML iis JavaScript jQuery Languages Launch maintenance Mato Microsoft Word Network Solutions Pantheon Parallax php php.ini podcast recaptcha recaptcha v3 responsive scss server slideshow submenu SVG transfer Translation vimeo wordpress WPML
Search Search

Recent Comments

  • Mike Armani on Avoid GoDaddy’s Dedicated Server
  • Nathan on Image Alignment Doesn’t Work in TinyMCE

Archives

  • September 2019
  • April 2017
  • September 2011
  • May 2010
  • February 2010
  • May 2009
  • April 2009
  • February 2009
  • January 2009
  • September 2008
  • August 2008
  • July 2008
© 1999-2026 ChristieMADE.com
  • Link to X
Scroll to top Scroll to top Scroll to top