How to print a custom menu in Drupal 7? - drupal

I have created a menu in Drupal 7 and created links to pages under that menu.
I named my new menu "Site Menu"
In my page.tpl.php where I want my menu to appear I have put this in place:
<?php print theme('links', menu_navigation_links('menu-site-menu')); ?>
After I have cleared my cache and refreshed my page my menu doesn't appear.
I am stumped. Any help would be greatly appreciated.

Berdir answer is correct. Drupal 7 theme_links function also more vastly uses arrays. For example if you would like to add another class name to the so that it is you would code it like this:
<?php print theme('links', array('links' => menu_navigation_links('menu-site-menu'), 'attributes' => array('class'=> array('links', 'site-menu')) ));?>

theme() now recieves an array of arguments. For example:
<?php
print theme('links', array('links' => menu_navigation_links('menu-site-menu')));
?>

Well, it is bit confusing from above solutions to print menu. But below code worked for me, hope this will work for y'all,
$search_menu_name = "menu-search-box-menu";
print theme('links', array('links' => menu_navigation_links($search_menu_name), 'attributes' => array('id' => $search_menu_name, 'class'=> array('links', 'inline'))));
The above code is like this, "menu-search-box-menu" is my custom menu name/ID. You can find it in that particular menu edit link.
Enjoy. :)

Related

Drupal 7 not showing sub menu

i am new to drupal and creating custom theme, i am using Main Menu but it is now showing sub-pages, i am using following code to show.
print theme('links__system_main_menu', array('links' => $main_menu, 'attributes' => array('id' => 'main-menu', 'class' => array('links', 'inline', 'clearfix', 'main-menu'))));
Please let me know what to do ?
thanks in advance.
Using this method will not render the sub items of a menu item. In order to have a menu with multiple levels you can either:
Use the available Main menu block available under admin/structure/block
Change the $main_menu variable passed to the template by using a preprocess function
In template.php of your theme:
function YOURTHEME_process_page(&$variables) {
$menu_tree = menu_tree_all_data('main-menu');
$variables['main_menu'] = menu_tree_output($menu_tree);
}
In your template file (page.tpl.php)
<?php print render($main_menu); ?>

Excluding posts from menu wordpress

I am trying to exclude multiple posts from the menu by the wp_nav_menu exclude parameter but that does not work the way I want it. Only page with id 58 is excluded If I run the following lines of code:
<?php wp_nav_menu( array(
'exclude' => '58, 59, 60',
'fallback_cb' => 'bfa_page_menu'
) ); ?>
If I pass the IDs as an array the menu just crashes.
Any help is much appreciated.
This is covered here http://9-sec.com/2012/10/how-to-exclude-pages-from-wp_nav_menu-2/
The other option is to use a custom walker function.

Creating a drop down menu

Full disclosure: I feel like this is a really dumb question, but I'm brand new to Drupal and am having quite a time getting something so simple to take place. I'm used to the Wordpress community so finding things on Drupal has been a challenge. Maybe it's a lack of help compared to WP or maybe it's just that I haven't learnt quite how to look for (or where to look for) what I need.
Whatever the case. I've sliced up a designers work and laid it atop Zurb's Foundation. I'm now in the process of placing this over the Bartik theme (feel free to point me in another direction if this is a bad choice..).
Here's how the menus are setup in Baritk, with slight tweaking by me (ie taking the header out):
<?php if ($main_menu): ?>
<?php print theme('links__system_main_menu', array(
'links' => $main_menu,
'attributes' => array(
'id' => 'main-menu-links',
'class' => array('main-nav'),
)
)); ?>
<?php endif; ?>
and
<?php if ($secondary_menu): ?>
<?php print theme('links__system_secondary_menu', array(
'links' => $secondary_menu,
'attributes' => array(
'id' => 'secondary-menu-links',
'class' => array('links', 'inline', 'clearfix'),
)
)); ?>
I've set the secondary links to read from the Main Menu I've setup which has the main pages and subsequent sub pages. This is the best setup, right?
If so, what's the best Drupal-esque way to merge these two? Is there an easier call, function, etc. besides using both of these separately?
The easiest way for you is probably to use the nice menus module.

List child pages of the current page's parent

I'm developing a WordPress theme using version 3.5.1, and in every page I want to display a side vertical menu displaying all the pages that belong to the current's page parent.
I've tried with this:
<?php
$args = array(
'sort_column' => 'menu_order',
'child_of' => $post->parent
);
?>
<ul>
<?php wp_list_pages($args); ?>
</ul>
But what I get listed is every parent page, instead of what I pretend to do.
What is the best approach to do this?
Thank you very much in advance!
That's a syntax error.
Try this: 'child_of' => $post->post_parent
That should return the siblings of the page you're in.

Why aren't my drupal 7 submenu's showing?

I can't seem to get my sub-menus to display.
I've gone to: Home » Administration » Structure » Menus
Then, I've edited the parent menu and checked the tickbox that says "Show as expanded" - but still nothing.
The code on my page.tpl.php page for the navigation I'm referring to, is as follows:
<?php
if ($page['navigation'] || $main_menu):
?>
<?php
print theme('links__system_main_menu', array(
'links' => $main_menu,
'attributes' => array(
'id' => 'nav',
'class' => array('links', 'clearfix'),
),
'heading' => array(
'text' => t('Main menu'),
'level' => 'h2',
'class' => array('element-invisible'),
),
));
?>
<?php
print render($page['navigation']);
?>
<?php
endif;
?>
What am I doing wrong?
Any help would be GREATLY appreciated.
Make sure that the parent menu "Show as expanded" attribute is checked.
Go to admin/structure/menu/item/MENU_ITEM_ID/edit, and check "Show as expanded"
Instead of using the $main_menu variable, you can use the main-menu block, which is generated with the menu.
If you put the "Main menu" block into the "Navigation" region at admin/structure/block, print render($page['navigation']) in the page.tpl.php will print out the complete menu, including its sub menu items (children).
Just make sure you tick the "Show as expanded" option in the parent menu link.
Lastly, remove the "print theme" stuff, otherwise you end up with double menu's.
the page.tpl.php will look something like this:
<?php if ($page['navigation']): ?>
<div id="navigation"><div class="section clearfix">
<?php print render($page['navigation']); ?>
</div></div><!-- /.section, /#navigation -->
<?php endif; ?>
The stark theme out-of-the-box doesn't show submenuus in it's main menu either (2011/04).
If you however go to admin/structure/blocks, and drag the menu block to the header region in the stark theme, it has submenus.
You'll also have two menus then, the original one without submenus and the new one with submenus. You can disable the original one in admin/appearance/stark/settings.
$2c,
*-pike

Resources