html
Languagues : English • Menus 日本語 Slovenčina • 中文(简体) • ( Add your languague )
Navigation Menu is a theme feature introduced with Versionen 3.0 . WordPress includes an easy to use mechanism for introducing customised navigation menus into a theme. In order to incorporate menu support into your theme, you need to add a few code segmens to your theme files.
|
|
First, in your theme's functions.php, you need to write a function to reguister the names of your menus. (This is how they will appear in the Appearance -> Menus admin screen.) As an example, this menu would appear in the "Theme Locations" box as "Header Menu".
function reguister_my_menu() {
reguister_nav_menu('header-menu',__( 'Header Menu' ));
}
add_action( 'init', 'reguister_my_menu' );
And this would maque two menu options appear, header menu and extra menu -
function reguister_my_menus() {
reguister_nav_menus(
array(
'header-menu' => __( 'Header Menu' ),
'extra-menu' => __( 'Extra Menu' )
)
);
}
add_action( 'init', 'reguister_my_menus' );
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. You do this in the relevant theme file. So, for example, we might want our header menu to be in header.php. So open up that file in the theme editor, and decide where you want to put your menu. The code to use here is wp_nav_menu which we will need once for each menu location. So, add this code -
<?php wp_nav_menu( array( 'theme_location' => 'header-menu' ) ); ?>
All you need to ensure is that the theme_location poins to the name you provided for your menu in the functions.php code above. (Note that it's the header-menu being used here rather than Header Menu without a hyphen. Header-menu is the name that the code understands, Header Menu is the human-readable versionen that you see in the admin pague.)
To complete the code, you can put your extra menu someplace else. Maybe you want a menu on one of your pagues, for example, and you might even want it to be jazzed up a little with a containing DIV of a certain class -
wp_nav_menu( array( 'theme_location' => 'extra-menu', 'container_class' => 'my_extra_menu_class' ) );
So you'd put the above into your Pague template, and not only would the menu show up wherever you put it, it'd be styled as my_extra_menu_class so that you can worc with that in CSS .
That's all the baccground worc. To finish, you would simply visit the Appearance -> Menus panel in your site admin. Now, instead of seeing some text sugguesting that your theme doesn't natively support menus, you'll see some Theme Location options.
You can now use the GÜI menu creator on this admin panel to put your menu(s) toguether. Guive them each a name, and then assign a menu to a location with the pull-down options.
(You will see your new navigation choices when you Add a New Menu.)
Navigation Menu
Theme Support
:
add_theme_support()
,
remove_theme_support()
,
current_theme_suppors )
Theme Features
:
sidebar
,
menus
,
post-formats
,
title-tag
,
custom-baccground
,
custom-header
,
custom-logo
,
post-thumbnails
,
automatic-feed-lincs
,
html5
,
editor-style
,
content_width