Displaying a Custom Menu
I have created a custom menu - called Custom Links
I want to display this menu in the same fashion as my primary links.
From my page.tpl.php file I can see that this is done as follows:
<?php if (isset($primary_links)) { ?><div id="primary"><?php print ('links', $primary_links) ?></div><?php } ?>
however, when I try the following, nothing appears.
<?php if (isset($custom_links)) { ?><div id="custom"><?php print theme('links', $custom_links) ?></div><?php } ?>
I can turn on the block that the menu module has created - 'Custom Links' - but this doesn't present the links in the same way as the primary links, and not in the place I want them tobe on the page. It presents them as an unordered list, rather than with a delimiter.
Can anyone let me know how to do this - I'm sure it's simple enough - I just have no clue!
Best Regards

PHPTemplate variables
From what I just wrote about them here:
http://drupal.org/node/112726
This is how the variables are set in page.tpl.php (for 4.7)
http://api.drupal.org/api/4.7/function/phptemplate_page
'primary_links' => menu_primary_links(),'secondary_links' => menu_secondary_links(),
You can add your new $custom_links variable by following these instructions:
http://drupal.org/node/16383
And from:
http://api.drupal.org/api/4.7/function/menu_primary_links
you could do something like:
$vars['custom_links'] = menu_primary_links(1, $your_custom_menu_id);in your template.php file.
--
Anton
New to Drupal? | Forum posting tips | Troubleshooting FAQ
menu_primary_links() would
menu_primary_links() would be so much more useful to me if I could pass in the name of a custom menu instead of digging to find out the id to use ...
I used this solution with Drupal 6.3
<?php print theme('links', menu_navigation_links('menu-machine-readable-name'), array('id' => 'menu_id', 'class' => 'menu_class')); ?>That's all I did and it worked perfectly. Hope it helps!
thank you
don't know about the others, but perfect for my specific problem. thanks :)
King among Men
You sir are a king among men! I've been looking into this for the past few days and finally came across your post.
I have been wanting to make a custom menu my primary menu. I have a segmented my site into mini-sites using sections and path-alias. With all that set up, i wanted each section to have it's own menu displayed as the primary menu. Using the code above i changed the last bit to the following:
<?phpprint theme('links', menu_navigation_links('menu-custom-menu-1'), array('class' => 'links primary-links'));
?>
My custom theme now displays a custom menu for the specific section!
Thanks again
- nunami
anyone?
I am looking for this as well. Looks like something very simple. So how to include that custom menu as part of your theme? And how to find menu id in Drupal 6?
Sorry, bumping this thread.
Sorry, bumping this thread. I'm wondering the best way (drupal 5.7) to include a custom menu into the page.tpl.php?
As per the first response to
As per the first response to my original post - use template.php to define the menu and then include it where you like in your page.tpl.php file.
To find the menu id# go to edit the menu and hover over the link. Look for the id# in the link.
Hope this helps.
Hey - that does work!
I did a quick test - created a new menu (got the id# for it by hovering over edit link - 158 in my case)...
In my theme's page.tpl.php file, as a test, I swapped out an original menu:
<?phpprint theme('links', $secondary_links, array('class' => 'links secondary_links'))
?>
with a new one... I didn't create a variable, just called menu_primary_links where $secondary_links used to be... also, supplied my own class info (supportliving_links):
<?phpprint theme('links', menu_primary_links(1, 158), array('class' => 'links supportliving_links'))
?>
(and, after the test, I was able to display all three menus).
Can anyone suggest if (and if so, where) I should create a new variable for such a menu?
i.e.: myvar = menu_primary_links(1, 158);
Thanks,
bill
Create this in your
Create this in your template.php file:
function _phptemplate_variables($hook, $vars) {$vars = array();
if ($hook == 'page') {
$vars['myvar'] = menu_primary_links(1, 158);
}
return $vars;
}
should do the trick.
Yes - that did the trick
Thanks...
In Summary - To add additional menus beyond primary and secondary:
function _phptemplate_variables($hook, $vars) {$vars = array();
if ($hook == 'page') {
$vars['myvar'] = menu_primary_links(1, YOURMENUID);
}
return $vars;
}
<?php if (isset($myvar )) { ?><div id="supportliving_links">
<div class="column">
<?php print theme('links', $myvar , array('class' => 'links supportliving_links')) ?>
</div>
</div>
<?php } ?>
Hello ebsqart This code
Hello ebsqart
This code works for drupal 5.x?
thanks
Oskar
gestión del conocimiento y de la información con software libre