Friday, September 10, 2010

How to create Header/Footer Menu in Drupal site

When you create any content from Drupal admin then you can choose "Parent Item" i.e (Primary Links / Secondary Links) from Menu settings tab for that item.

Header Menu

In Drupal theme (page.tpl.php), all parent menu links are available in $primary_links array. You can just loop through the array elements and print all menu items in header.

<?php if ($primary_links){ ?>
<ul>
<?php  
foreach($primary_links as $value){
  echo '<li><a href="'.$base_path . drupal_get_path_alias($value['href']) .'">'.$value['title'].'</a></li>';
}
?>
</ul>
<?php } ?>


Footer Menu

In Drupal theme (page.tpl.php), all secondary menu links are available in $secondary_links array. You can just loop through array elements and print all menu items in footer.

<?php if ($secondary_links){ ?>
<ul>
<?php  
foreach($secondary_links as $value){
   echo '<li><a href="'.$base_path . drupal_get_path_alias($value['href']) .'">'.$value['title'].'</a></li>';
}
?>
</ul>
<?php } ?>

No comments:

Post a Comment