i would like to show the submenu of my page in a custom page template on the left side in a Sidebar-area. Does any know the code for showing the submenu.
I'm using Wordpress 3.4.1.
Register Menus
Firstly, in your theme's functions.php, you need to write a function to register the names of your menus.
function register_my_menus() {
register_nav_menus(
array( 'sidebar-menu' => __( 'Sidebar Menu' ) )
);
}
add_action( 'init', 'register_my_menus' );
Display Menus on Theme
Once you've done that, your theme will be almost ready. The last preparation step is to tell the theme where you want the menus to show up.
<?php wp_nav_menu( array( 'theme_location' => 'sidebar-menu' ) ); ?>
That's all the background work. To finish, you would simply visit the Appearance -> Menus panel in your site admin.
Please read the wordpress codex site.. it has plenty of information on how to do this..
http://codex.wordpress.org/Navigation_Menus
Related
I have converted my one page html website to wordpress theme. Index.html page is converted to header.php, index.php and footer.php .
Now I want to make a dynamic menu. I have registered my menu in WordPress and it I showing in the admin panel. When I create a new menu now the page is showing to add my menu there. How can I create that page?
You may need to register the menu via functions.php.
If you dont have, create a file inside your theme as functions.php and paste the following code to register the menu.
register_nav_menus( array('my_nav' => __( 'Primary Navigation', 'dz theme' ),
'secondary' => __('Secondary Navigation', 'dz theme')
));
And you can call your primary menu as :
<?php wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'my_nav' ) ); ?>
I am re-building our Learning Management System using WordPress. We use bootstrap and navwalker for the upper (main) navigation. I'd like to have another upper (main) navigation when the student is logged in. How would I go about this? Woudl you recommend my developer creates a different PHP Header Request?
So, at the moment all templates have this function:
<?php get_header();
Woudl the sensible thing be to create all the templates that need a different navigation like this:
<?php get_header(logged-in-templates);
So, the 'logged-in-templates) pull in the different navwalker...
Hope that makes sense!
Thanks
As i understood you want to display different nav menus if user is logged in and if the user is not logged in. In such case you can register additional nav menu location in functions.php:
register_nav_menus( array(
'logged_in_menu' => esc_html__( 'Menu for logged in users', 'yourthemename' ),
) );
and then just check
if(is_user_logged_in()) {
wp_nav_menu( array( 'logged_in_menu' => 'yourthemename' ) );
} else {
wp_nav_menu( array( 'primary_menu' => 'yourthemename' ) );
}
Is this what you are looking for?
I have a fresh install of WordPress 4.0.1 running Twenty Fourteen theme with no plugins activated.
When I go to Appearance > Menus, I only see one tab "Edit Menus". "Manage Locations" tab that I used to have in earlier versions is missing.
When I create a new menu, it's not visible. However, if I try to create a new menu with the same name, I get an error message, "The menu name TESTMENU conflicts with another menu name. Please try another."
It turns out some themes does not have menu locations and you need to add theme manually through your theme's functions.php. Anyhow, here's what I did:
add_theme_support( 'menus' ); // <-- if you already see `menus` from your settings menu, you can ignore this line.
function register_menus() {
register_nav_menus(
array(
'primary-menu' => _( 'Primary Menu' ) // add locations here.
'your-preferred-menu-location-id' => _( 'Title of your menu location' )
)
);
}
add_action( 'init', 'register_menus' ); // <-- of course without this, the function above will not execute.
If the code above does not work for you, try enable/disable plugins that might be causing the issue.
Hope this helps.
I am developing a site in Wordpress. I am using a theme named Moesia. While customizing the the theme according to my website needs, i found that the theme only supports one menu which is the main menu at the Top Right.
I want to add another menu which will only be visible inside a page. I have tried to add custom menu to a page, the issue that when I click on a menu item the whole page refreshes and the menu goes away. I want the menu to stay on that page and a click on the menu item should display the content adjacent to the menu.
I am absolutely new to this technology.
How can I achieve this?
Add the following to your functions.php file. The 2 menus are the “Primary”, and “Secondary” menus.
//Register Navigations
add_action( 'init', 'my_custom_menus' );
function my_custom_menus() {
register_nav_menus(
array(
'primary-menu' => __( 'Primary Menu' ),
'secondary-menu' => __( 'Secondary Menu' )
)
);
}
To add them to your site you need to add the following to your WordPress template files (most likely your header.php and footer.php files).
<?php wp_nav_menu (array('theme_location' => 'primary-menu','menu_class' => 'nav'));?>
<?php wp_nav_menu (array('theme_location' => 'secondary-menu','menu_class' => 'nav'));?>
My theme has several custom menus. I can manage them in the WP admin panel.
But look at the picture. You see 2 menus already created - Footer Menu and Header. But in my case those 2 names do not appear so I cannot do anything with them later.
Code I used:
add_action( 'init', 'menus_all' );
function menus_all() { register_nav_menus( array(
'menu1' => _( 'menu1 loc'),
'menu2' => _( 'menu2 loc'),
) ); }
How to make the menu names appear ?
register_nav_menu goes straight in your functions.php file, without any hook:
register_nav_menus( array(
'menu1' => _( 'menu1 loc'),
'menu2' => _( 'menu2 loc'),
));