3.0 Menus and Arthemia
WordPress 3.0 came out weeks ago, but I just recently got around to updating. Over the years one of the biggest problems I have faced when a new version of WordPress is released is that things get whacked out with whatever theme I happen to be using. Well, thus far everything seems to be working pretty well with Arthemia (knocks wood). One of the new features in WP 3.0 is a much more robust interface to handle the creation of custom menus. This is handy to know, because the plugin that I use manage my recipes has been updated to (among many other things) take advantage of this new functionality. There are a few things that you have to do first however to get the new menu scheme working in an older theme like Arthemia however. WordPress uses a new function called wp_nav_menu. If you go to your dashboard and click on Appearance > Menus, you will see the following message:
“The current theme does not support menus.”
The first thing that you have to do to add this functionality to Arthemia (or any other pre-3.0 theme for that matter) is open up the functions.php file in your theme folder.
In that file, you want to add the following code:
if (function_exists('add_theme_support')) {
add_theme_support('menus');
}You can add this pretty much anywhere, but the best place to insert it is just before the last
?>
this will ensure that you don’t mess with any other functions already in the file. Save the functions.php file and close it.
Now you can go to Dashboard > Appearance > Menus and you will see that the the menu function is now supported. In this window, you first want to give your menu a name. Since I am replacing Arthemia’s navigation menu, I will call mine “Site Navigation” but you can really call it anything you want. Giving the menu a name allows you to place multiple menus in any template file. After naming and saving the custom menu, you have several options to add and organize the links in the menu. For example, you can select the Pages and Categories you want to add then click the Add to Menu button. Note that you can also add custom links to either internal or external url’s. You can also drag the menus into any order that you want. Set the menu up however you like and save it. You can now close the menu management window.
Finally, to add the new menu to your theme, open up the template file where you want the menu. In Arthemia, I want to simply replace the main navigation at the top of the page, so I open up the header.php file. Here you want to add the code:
<?php wp_nav_menu('menu=Site Navigation'); ?>To wherever you want the menu to appear.
(Note that “Site Navigation” is what ever the custom menu name you gave the menu)
In Arthemia look for the code:
<li><a href="<?php echo get_option('home'); ?>/">Home</a></li>
<?php wp_list_pages('sort_column=menu_order&title_li='); ?>
</ul>and replace
<?php wp_list_pages('sort_column=menu_order&title_li='); ?>with
<?php wp_nav_menu('menu=Site Navigation'); ?>this leaves the “Home” menu item in place, and adds your custom menu after it. If you wanted to get rid of the home menu you could delete that as well, just make sure you leave the list tags in place so that the menu styles correctly. There are tons of parameters available to the custom menu, many of which allow you to assign classes and tags. To see the code that is actually added to the page, open it up, control+click (or right+click) on the code, and select “view source” and you should be able to figure out how you can style it to your hearts content. So that is it – WordPress has done an excellent job creating a way for you to have an infinite number of custom menus.








Ironically we’ve ran into some hair pulling css bugs with wp_nav_menu() with IE6, drop down menus. We are just going with:
————————-
‘primary-menu’, ‘depth’ => 3 ) ); ?>
————————-
We redid the CSS but we still can’t get the hover to work. AHH!
Yes. That’s because hovering other elements than anchors doesn’t work on IE6. And I guess IE7 too. If you find a way to do it in CSS please let me know: lucassp@gmail.com.
Leave your response!
advertisement:
and another thing...
October 22, 2011 | 3:16 am
Hoo-wee it is cold in Paris!
October 9, 2011 | 9:59 am
But I do know when I will be back again. Returning from San Francisco on a Thursday morning red-eye.
October 5, 2011 | 8:51 am
October is going to be a busy month with lots of work travel. It is all good, but I woke up this morning already looking forward to November.
March 30, 2010 | 9:00 pm
A man goes to the brain clinic to get a fresh set of brains. At the front desk is a sign that says “Doctor Brains: $20 per ounce. Scientist Brains: $30 dollars per ounce. Architect Brains: $1000 per ounce.”
$1000 dollars per ounce!” the man exclaims, “Why are architect brains so expensive!?!”
“Because it takes a loooooot of architects to get an ounce of brains,” replies the receptionist.
blogs
links