I really like the drop down menu solution of twenty eleven theme:
http://twentyelevendemo.wordpress.com/
and would like to create a similar one but I cannot figure how it works, or is it based on some existing code for dropdown menus?
Is there any source code that can be used, or can someone explain the principle behind it?
I know internet is full of both js and non-js solutions, I’ve even made some myself, but IMO nothing comes near this menu, so help is appreciated:)
I was just doing exactly this recently. Not sure how advanced you are so you may know some of this stuff already.
I found this video to be very good (+ it’s second part)
I think one of the original pieces of research done was this
I think Twenty Eleven also uses the superfish jquery plugin
As the other poster mentioned you can find the twenty eleven code itself somewhere amongst the theme files
Here is a quick snippet I use to get started on my projects:
The first step is to add some code to the functions.php file. This is what will enable the WordPress Custom Navigation. The controls will be in Appearance>Menu’s once your finished.
Code for functions.php:
The code above allows for two menu’s. I’ll show you how to add one, and if you want you can use the same method to add a second wherever you wish.
The next step is to add the code to the header.php file. Notice above that the first menu in the array is labeled main. This is what we’ll use to place the menu in the header.php.
Here is the code for the header.php:
This should be placed inside your
<div id="header">
div’s (it isn’t mandatory, but is the most common place for the code.The last step is to add some CSS to style the menu and actually make it “drop-down”, instead of a bunch of multilevel links.
The CSS code:
You can play with the css to adjust it to your liking, but that should get you started.
Edited For WordPress 3.3 Compatibility:
After updating to the latest version of WordPress (v3.3) it appears the menu’s won’t work if your theme is using the after_setup_theme hook and you use the ‘init’ hook to register the menu’s.
The Fix:
For this example I’ll use the name yourtheme as the function_name.
Sample functions.php file:
Look at the TwentyTen Themes functions.php file to see other functions to include in the after_theme_setup hook.