Attach a specific menu to a specific page - wordpress

In my Wordpress website:
I have two pages, one is in Deutsch and one is in English.
I have two menus, same deal.
I would like to display the english menu when browsing the page in English and display the deutsch menu when browsing the page in Deutsch.
I cannot use any multilingual pluging unfortunately.
Is there any way to achieve this with a basic wordpress installation?

Why can't you use a multi-language plugin?
Assuming you're right about the idea of not being able to use such a plugin, two solutions come to mind:
Use custom fields and conditional logic to display one menu or another
Use page templates to display different menus
You can override the layout of a page by creating a file called page-{slug}.php or page-{id}.php, in which {slug} and {id} should be substituted for the slug or id of the page you wish to make a template for. In this page template you could copy the original layout, but alter the wp_nav_menu command to select a different menu.
There are a few other ways to do it, but those two seem like sensible options to me.

Try this one:
Put this code in header.php while calling navigation menu:
<?php if (is_front_page()) { ?>
<div id='frontPageBanner'>
<?php wp_nav_menu( array( 'container_class' => 'menu-header-1', 'theme_location' => 'primary' ) ); ?>
</div>
<?php } elseif (is_archive()) { ?>
<div id='archiveBanner'>
<?php wp_nav_menu( array( 'container_class' => 'menu-header-2', 'theme_location' => 'primary' ) ); ?>
</div>
<?php } elseif ( is_page($pageID)) { ?>
<div id='pageIdBanner'>
<?php wp_nav_menu( array( 'container_class' => 'menu-header-1', 'theme_location' => 'primary' ) ); ?>
</div>
<?php } ?>
Thanks.

Related

how can i set different menus on different pages in wordpress?

I am trying to setup diffrent menu for diffrent page like.
In Home Page I need to main menu link like this
<a href='#home'>Home</a>
<a href='http://example.com/product'>Product</a>
<a href='#services'>Services</a>
<a href='#conact'>Contact Us</a>
In product Page
<a href='http://example.com/#home'>Home</a>
<a href='http://example.com/product'>Product</a>
<a href='http://example.com/#services'>Services</a>
<a href='http://example.com/#conact'>Contact Us</a>
I am using one page theme so please help me for this logic development.
Thanks
It is impossible to answer this question without seeing more code, but in an abstract sense this can be achieved quite easily. As Yatendra pointed out, you need to register two menus as so in your functions.php file:
function register_my_menus() {
register_nav_menus(
array(
'home-menu' => __( 'Header Menu' ),
'product-menu' => __( 'Product Menu' )
)
);
}
add_action( 'init', 'register_my_menus' );
Then, you will want to embed something similar into your header.php where you navigation should like usding the is_page_template() and wp_nav_menu() functions.
<?php
if (is_page_template( 'products.php' )) // change this to the name of the file
{
// load the product-menu
wp_nav_menu( array( 'theme_location' => 'product-menu' ) );
}
else
{
// load the header-menu
wp_nav_menu( array( 'theme_location' => 'header-menu' ) );
}
?>
However, for a one-page theme, something like a parallax theme you are better not putting in a conditional and wrapping them in <div> tags and show and hiding them with jQuery. However, we would really need to see more code.
Codex References:
is_page_template()
Registering a Menu

wp_nav_menu not working on category pages on wordpress

I created a couple of custom menus on wordpress using the appearance menu.
I want to display the right menu according to the page that I'm viewing. I wrote the script below in the header.php file in the seems to be working fine. It's pulling the correct menu according to the page that I'm visiting with the exception of the category pages.
When I'm on a category page, the wp_nav_menu function falls back to the fallback function, indicating that the menu doesn't exist?!
I was looking around and the solution that kept coming up was adding the following code but it doesnt seem to work.
<?php
wp_nav_menu('container_class=menu-header&theme_location=primary');
?>
Here is the full code that I added to the header.php file:
<?php
switch( $master_page ) {
case 'about':
wp_nav_menu(array(
'menu' => 'about',
'fallback_cb' => 'get_cat',
));
break;
case 'offer':
wp_nav_menu(array(
'menu' => 'offer',
'fallback_cb' => 'get_cat',
));
break;
}
?>
I'm really frustrated at this point. Any ideas?
I don't see where you are assigning a value to $master_page, so at this point it is just an empty variable.
You need to look into the is_page() and is_category() functions in WordPress and use if statements rather than a switch.
<?php
if( is_page( 'about' ) ) {
wp_nav_menu(array(
'menu' => 'about',
'fallback_cb' => 'get_cat',
));
} else {
...
}
?>

Insert another menu into WordPress... not working at all?

I am following this guide to "Add additional support for menus in your theme":
http://codex.wordpress.org/Navigation_Menus
I followed all of the steps, but this is the result:
http://puu.sh/30bMt.png
So, it's "inserting a menu" where I told it to.... however the items on the menu do not match up with what I have in the WordPress back-end, seen here...
http://puu.sh/30bQd.png
I only inserted 4 items into the menu "Test"... but it's displaying every page, instead of the 4 items I want.
I've attempted to do research to figure out what's going on to no avail; does anybody have any insight as to why this is acting funky?
Code where I'm "registering" the additional menu support... (themes function.php):
function register_my_menus() {
register_nav_menus(
array(
'header-menu' => __( 'Header Menu' )
)
);
}
add_action( 'init', 'register_my_menus' );
Code where I'm inserting the "Header Menu" itself... (themes header.php):
<?php
wp_nav_menu( array( 'theme_location' => 'extra-menu', 'container_class' =>'my_extra_menu_class' ) );
?>
If you are trying to call 'Header Menu' then the code in your header.php should look like this:
<?php wp_nav_menu(array('theme_location' => 'header-menu', 'menu_class' => 'my_extra_menu_class')); ?>
I'm not sure where you got 'extra-menu' from but WordPress doesn't know what that is since you didn't declare that in your register_my_menus function.
I hope that helps.
Here's an example of how I've implemented multiple menus in my WordPress install:
// Register Extra Menus
function new_register_menus() {
register_nav_menus(array('Products'=>'Products Nav', 'Support'=>'Support Nav', 'Company'=>'Company Nav' , 'Footer'=>'Footer Nav'));
}
add_action( 'init' , 'new_register_menus' );
//Code in my footer.php
<?php wp_nav_menu(array('theme_location' => 'Footer', 'menu_class' => 'nav')); ?>

How do I get second level menu in Wordpress?

I'm over 2 hours trying many functions (wp_list_pages, get_pages, wp_nav_menu) and several functions but can't resolve this thing out.
I have created pages that are THREE level deep:
PAGE level1
SUBPAGE level2
SUBPAGE level3
and I need to display a separate menu for each of them like:
MENU1 (all top-level pages)
MENU2 (all sub-pages of CURRENT top level page)
MENU3 (all sub pages of current item from MENU2)
it should not be that complicated for a CMS like Wordpress but I think I'm over-complicating possible solutions.
Do you have some suggestions on possible ways to achieve that?
Thanks.
First of all you have to define accordance between menu items and pages. I can't define this accordance from your question. What if you have two level2 subpages and two menu2 items? Which menu item belongs to which subpage?
Then the process is trivial. You can get all menu items
$menu_items = wp_get_nav_menu_items($cur_menu, array());
And check menu_item_parent field to found parent items
foreach ($menu_items as $item) {
if ($item->menu_item_parent === $parent_id) {
//this is child of $parent_id
}
}
If you are using the the WordPress Function register_nav_menus() , it should be fairly simple.
In your functions.php file you'll need to register 3 separate menu's, something like this:
<?php
add_action( 'init', 'register_my_menus' );
function register_my_menus() {
register_nav_menus(
array( 'first' => 'first', 'second' => 'second', 'third' => 'third', )
);
}
?>
With the menu's now registered you just need to place them where they go in your theme files like so:
The First Menu (maybe in the header.php file)
<div id="menu">
<?php wp_nav_menu( array( 'theme_location' => 'first' ) ); ?>
</div>
The Second Menu (maybe in the sidebar.php file)
<div id="menu">
<?php wp_nav_menu( array( 'theme_location' => 'second' ) ); ?>
</div>
The Third Menu (maybe in the footer.php file)
<div id="menu">
<?php wp_nav_menu( array( 'theme_location' => 'third' ) ); ?>
</div>
The final step is to go to Appearance>Menu's and create the 3 menu's, name them and choose the pages that will go with them from within the Admin Menu Settings.

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