Add subitem to second level

2019-08-05 05:34发布

问题:

I have primary links created manually. The are links to node (content type 'page') like

-About
--About Us
--About company

I need to add subitems About/About company/company1 and About/About company/company2 from my module.

Next lines create menu item in first level (in one level with -About)

$items['about2'] = array(
  'menu_name' => 'primary-links',
  'title' => 'About2',
  'page callback' => 'ninegm_about2',
  'access callback' => TRUE,
  'weight' => -10,
);

回答1:

Check out the documentation at the Drupal API site. The path of the menu item, and the hierarchical organization, is determined by the key you pass to $items when defining a new menu item. Right now you are making a completely new top-level menu item.

So you need to replace $items['about2'] with something like this:

$items['About/About company/about2'] = array(
//rest of menu item definition . . .

This will make the new menu item a child of the menu items in its path, so it will come out looking like this:

-About

--About Company

---About2

This is assuming the path to your root about page is "About", and the path to your About Company page is "About company". If that isn't true, just replace them with the real paths to those pages.