Drupal 7 Tutorial Part 8: How to create a menu and add links to it in Drupal 7

posted Jun 23, 2011, 2:56 AM by admin@ revitviet.vn   [ updated Jun 23, 2011, 5:48 AM ]
Hi Drupalers,

In last tutorial , we learnt about drupal 7 default menus and different menu settings. In this tutorial we will see how to create a new menu from scratch and how to add new links to the menu.

Let's create a menu with links to some of commonly used administrative links and display only to administrators. This menu will help to quickly navigate to the links.

Creating new menu:

  • Login as administrator and goto home page. Click on Structure link on top main menu. Then, click on Menus link.
  • Now you will screen some thing like below.

  • In the above screen, click on Add menu link to create a new menu. Once you click on Add menu link you will screen some thing like below.

  • We need to provide title and description for our new menu. Let's title the menu as Administration Shortcuts and give description as This menu is used to navigate quickly to most commonly used administrative links. Now click on save button below the form. Once you save the form you will see the screen something like below. Screen shows with a status message  "Your configuration has been saved."

  • Let's add some links to our new menu and see some advanced settings while adding links. Click on Add link text as shown in above screen to add a new link to our menu.
  • Once you click on add link you will see screen something like below to create a new link.

  • Let's create a link to listing of blocks page. Link is "admin/structure/block" . Fill the Menu Link title as "Blocks Landing Page", path as "admin/structure/block", Description as "Blocks listing page", and click on save. You can see confirmation message "Your configuration has been saved" and now you are in our new menu "Administration Shortcuts" links listing page.
  • You can see Add Link text in the listing page. click on that link to add one more link to our "Administration Shortcuts" menu.
  • Let's add link to "User listing" page. Path to this page is "admin/people".  Give title as "User Listing", description as "List of all users". Click on save. We just added two links to our menu.
  • Now you can see two links in menu listing. Now let's enable this menu for administrators in the left side bar.
  • Normally, when we create a menu, Drupal automatically creates a block that displays our menu links. So, when ever a menu is created with link a block will be automatically created for that menu.
  • Let's go to block listing page, to enable our menu which is block format. Click on                           Structure >> Blocks to access blocks listing page. In the blocks listing page when you scroll down you can see Administrative Shortcuts block in the disabled section like in below screen.

  • Let's enable Administration shortcuts in left side bar and only for administrators. As you see in above screen, change the select box value next to "Administrative Shortcuts" text from - None - to  sidebar first. When you change the value the row will be automatically moved to Sidebar first section in block listing page. Only when you click on "Save blocks" button at bottom then only settings will be saved. Click on save blocks button to save settings.
  • Now go to home page to see our new menu in the left side bar. If you want to enable this block only for administrators go to block configure page from block listing then set visibility conditions to  only administrators. My previous tutorial will help you, to set visibility permissions only to administrators.

  • So, we created a menu from scratch and displayed it using block in the left side bar.
  • If you want to add more links to the same menu, go to Structure >> Menus >> Add Link (Next to Administrations Shortcuts in the list of menus) .

Let's see more menu settings, parent child relation ship of menus, changing order of menus, global menu settings in my next tutorial. Stay tuned with me.

Please feel free to comment if you have any issues.

Cheers,

Anil Sagar

 

Comments