0
votes

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).

  1. 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').

  2. 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?

1

1 Answers

0
votes

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.