WP - how to create menus - wordpress

Could you please explain me how do I properly create wordpress menus? I just want two menus on my website - with pages, and the other one with categories (by default).
Should I put html code for these menus in two separate files? Or rather put all id's in the array parameter of wp_nav_menu()? Tried the first one but the separate file nav-something.php doesn't seem to be loading ('theme_location' => 'nav-something').
If I want to display categories in the menu, should I simply use wp_list_categories()? Will user be able to change this in the future from admin interface?

Firstly You have to create the both menus under Appearance > Menu
Add below code where you want to show on the page. But you need to select the one menu as a primary menu in admin section. You can do this in Appearance > Menu > Primary Navigation
<?php wp_nav_menu( array( 'theme_location' => 'primary' ) ); ?>
For your category menu add new menu in admin section under Appearance > Menu and give the name "Category Menu" and paste the below code where you want to show this menu. After that you need to add the categories in menu section. You can enable category listing in wordpress screen option(Right top section in admin panel.)
<?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu', 'menu' => 'Category Menu' ) ); ?>
Please note down I have given the same name in above code and in admin section "Category Menu". You can add more menus by adding above code but you just need to give the same name in code and in WordPress admin section.
If you Don't want to create category menu in admin section then you can add this code in you file.
<?php wp_list_categories(); ?>
You have both the options now its on you which one you want to use.

Related

How can I show different Menu on Different page?

I am using Asta Wordpress theme and its single page website with 4 menus. Now I have created 2 more pages but menu isn't working since it belong to homepage only. Is there any way I can set different menu for different pages?
usually all the pages follow page.php, have a look if you have header imported in page.php, if you want a different header menu, create a different header and rename as header-pages.php, assign a different menu here as
<?php wp_nav_menu(array(
'theme_location' => 'page_menu',
'container' => false,
'depth' => 3
))
?>
add this to your functions.php by editing the existing array
register_nav_menus( array(
-------remove this, add the below code only in existing array------
'page_menu' => esc_html__( 'Page Menu', 'website' )
-------remove this, add the above code only in existing array------
));

Wordpress menu using hash tags for single page but not when I load blog template

I am creating a single page wordpress site. The primary menu that is in header.php uses hash links to reference content in the page. All the content in the body of the webpage loads into page-home.php. One of the items in my primary menu however is Blog. Blog loads entirely different templates. Once you are in blog, the other menu items do not work because the hash links no longer have the content in the index.php templates to connect to. Should I conditionally load a separate menu for when the url is /blog/? Call a separate header on index.php?
No need for two header.php files. Inside your current header.php use this code
<?php
if(is_page('Home'){ //or whatever your home page is called
wp_nav_menu ( $arrayName = array( 'theme_location' => 'primary', 'container' => 'nav', 'container_class' => 'navbar-collapse collapse', 'menu_class' => 'nav navbar-nav navbar-right' ) );
} else{
//INSERT CODE FOR BLOG MENU
}
?>

how to set Primary Menu in wpmu automatically

when we create sub domain in wpmu the we create four page home,about,team,and contact.
page is created successfully.
But how to select these pages on Primary Menu.
For this you can set menu name in header.php file and when you add that menu in given menu it automatically showing in wordpress
<?php wp_nav_menu(
array( 'menu' => 'primary', // menu name in wordpress
'menu_class' => 'nav-menu' ) );
?>
it is very simple and you need not to set again and agin just carefully you menu name is primary or header or whatever.

How to allow my theme to support multiple menus in wordpress

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'));?>

Add Submenu in sidebar on wordpress

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

Resources