Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm pretty new with wordpress and I want to create my own dropdown menu without the use of any plugins. I have a few questions about this. I already did some research but there are some things i do not understand. In my header file I have the following code for my main menu.

<div id="navigation">
    <?php wp_nav_menu( array( 'theme_location' => 'primary' ) ); ?>
</div>

I didn't have to add any code in my function.php file. It worked well. In the most tutorial, you have to add this code in to the function.php file. But for me it worked without this code.

<?php
add_action( 'init', 'register_my_menus' );
function register_my_menus() {
register_nav_menus(
array(
    'main' => __( 'main' ),
    ));
}
?>

When I want to add a custom menu in wordpress I have to add something to this code.

<?php
  add_action( 'init', 'register_my_menus' );
function register_my_menus() {
register_nav_menus(
array(
    'main' => __( 'main' ),
    **'secondary-menu' => __( 'Secondary Menu' ),**
    ));
}
?>

From this moment on, i can see 3 menu's in the backend. (2X primary menu, 1X secundary menu) I know this was a lot but I have tried to be clear and i hope somebody will understand me. Can somebody please tell me where i'm going wrong? Thanks

share|improve this question
    
Is your question "How do I display a nav menu" or is it "I have a working nav menu, but how do I create drop down menus?" –  Tom J Nowell Jan 24 '13 at 10:17
    
@TomJNowell I have a workig nav menu and i want to create a dropdown menu. Above you see the things I already did. My question now is. Were this the right steps to create a dropdown menu? Is there something else i have to do or is just a matter of css now? –  Niels Jansen Jan 24 '13 at 10:21
    
Ah if you have a working menu then it is indeed a pure CSS question –  Tom J Nowell Jan 24 '13 at 10:46
    
@TomJNowell My main menu is fully working. It is just my submenu that is not working and I dont know if i did the right things (see above) to get it working. In my view that is not the right solution because a dropdown menu is not a secondary menu? –  Niels Jansen Jan 24 '13 at 10:50
    
Sub menus would be children, it's purely a CSS issue, look up CSS drop menus –  Tom J Nowell Jan 24 '13 at 10:59

1 Answer 1

For the moment based on your question I am assuming you want a single menu, which when hovering over a menu item, its child items are displayed in a drop down menu.

Following this tutorial should give you a horizontal menu with vertical drop downs:

http://codex.wordpress.org/Creating_Horizontal_Menus

Repeat for each menu you need.

For more on defining and using menus themselves in PHP, refer to this article by Justin Tadlock:

http://justintadlock.com/archives/2010/06/01/goodbye-headaches-hello-menus

share|improve this answer
    
Thanks for your answer, I was a little bit confused about the different types of menus you have in wordpress. I think I only have to change some CSS to 'create' my dropdown menu. I do not want an extra menu (secondary menu) so why do I have to change PHP code then. I think I understand it now and this is my conclusion. If you want a dropdown menu (hoover over an item, child item appears in dropdown) you only need to change some css. If you want an extra menu for example a primary menu and a secundary menu, you have to change the php code ect. Can you please tell me if i'm correct? –  Niels Jansen Jan 24 '13 at 17:22
    
How the menu appears is CSS based, not PHP. PHP defines the menu, CSS styles it. Dropdowns are not separate menus, they're a part of the main menu. –  Tom J Nowell Jan 24 '13 at 17:29
    
Thank you for explaining this. I'm going to "copy" the css from the twenty eleven theme :-). I will let you know if everything is done. –  Niels Jansen Jan 24 '13 at 17:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.