How to build a menu programmatically (Manually) with Drupal?

2k Views Asked by At

I have a menu in Drupal in the following structure:

-Gallery
--Gallery Item 1
--Gallery Item 2
--Gallery Item 3
--Gallery Item 4
-Videos
--Video Item 1
--Video Item 2
--Video Item 3

The Gallery and the Video items in the menu should be loaded dynamically from the content type gallery. My problem is that I don't know how to programmatically build and add menus items in the mentioned structure.

Thanks!

2

There are 2 best solutions below

1
On

-There's a module only available for Drupal 6 and below called Auto Menu - You can look at the source code and see how it's done, and convert it into a Drupal 7 module. Suggestion: Since its maintainers haven't committed for a long time, it's a chance for you to help out in the Drupal community by submitting your new module for Drupal 7.

-Alternatively, you can use the Views module and create a block to show the titles of your nodes as links, filtering by your desired Content Types and ordering by Content Type as well (to show Gallery items first, then the Video items).

-Plus, check out previous threads on this here and here.

0
On

As I have mentioned here, Menu Views is an interesting module for Drupal 7 to automatically generate menu links using Views. It integrates seamlessly with menu modules such as Superfish and Nice Menus.

(PS: my reputation is not high enough to provide more than two links, therefore I have marked the other modules bold instead of providing hyperlinks)