• 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細

このWikiはいつでも誰でも編集できます

「ナビゲーションメニュー」の版間の差分

提供: WordPress Codex 日本語版
移動先: 案内検索
(リンク・コード表示・カテゴリ調整/翻訳者募集中)
(見出しのみ訳)
1行目: 1行目:
 
{{NeedTrans}}
 
{{NeedTrans}}
  
=Navigation Menus=
+
=ナビゲーションメニュー=
  
 
WordPress includes an easy to use mechanism for introducing customised navigation menus into your theme.  In order to incorporate menu support into your theme, you need to add a few code segments to your theme files.  
 
WordPress includes an easy to use mechanism for introducing customised navigation menus into your theme.  In order to incorporate menu support into your theme, you need to add a few code segments to your theme files.  
  
== Edits to functions.php ==
+
== functions.phpを編集する ==
  
 
Firstly, in your theme's functions.php, you need to write a function to register the names of your menus. (This is how they will appear in the [[Appearance_Menus_SubPanel|Appearance -> Menus]] admin screen.)  As an example, this menu would appear in the "Theme Locations" box as "Header Menu".
 
Firstly, in your theme's functions.php, you need to write a function to register the names of your menus. (This is how they will appear in the [[Appearance_Menus_SubPanel|Appearance -> Menus]] admin screen.)  As an example, this menu would appear in the "Theme Locations" box as "Header Menu".
33行目: 33行目:
 
The above tells the theme to run your "register_my_menus" procedure.  As you can see, your new function makes use of the WordPress register_nav_menus functionality.
 
The above tells the theme to run your "register_my_menus" procedure.  As you can see, your new function makes use of the WordPress register_nav_menus functionality.
  
== Now add locations to your template files ==
+
== テンプレートファイルに場所を追加 ==
  
 
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|wp_nav_menu]] which we will need once for each menu location.  So, add this code -
 
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|wp_nav_menu]] which we will need once for each menu location.  So, add this code -
47行目: 47行目:
 
So you'd put the above into your Page 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 work with that in [[CSS]].
 
So you'd put the above into your Page 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 work with that in [[CSS]].
  
== Back to the Menus Panel ==
+
== メニューパネルに戻る ==
  
 
That's all the background work.  To finish, you would simply visit the [[Appearance_Menus_SubPanel|Appearance -> Menus]] panel in your site admin.  Now, instead of seeing some text suggesting that your theme doesn't natively support menus, you'll see some Theme Location options.   
 
That's all the background work.  To finish, you would simply visit the [[Appearance_Menus_SubPanel|Appearance -> Menus]] panel in your site admin.  Now, instead of seeing some text suggesting that your theme doesn't natively support menus, you'll see some Theme Location options.   
53行目: 53行目:
 
You can now use the GUI menu creator on this admin panel to put your menu(s) together.  Give them each a name, and then assign a menu to a location with the pull-down options.
 
You can now use the GUI menu creator on this admin panel to put your menu(s) together.  Give them each a name, and then assign a menu to a location with the pull-down options.
  
== Related Links ==
+
== 関連情報 ==
  
 
There's a reasonable tutorial on this [http://justintadlock.com/archives/2010/06/01/goodbye-headaches-hello-menus here] which has some more detail around the options available.
 
There's a reasonable tutorial on this [http://justintadlock.com/archives/2010/06/01/goodbye-headaches-hello-menus here] which has some more detail around the options available.

2015年5月8日 (金) 14:25時点における版

このページ「ナビゲーションメニュー」は未翻訳です。和訳や日本語情報を加筆してくださる協力者を求めています

ナビゲーションメニュー

WordPress includes an easy to use mechanism for introducing customised navigation menus into your theme. In order to incorporate menu support into your theme, you need to add a few code segments to your theme files.

functions.phpを編集する

Firstly, in your theme's functions.php, you need to write a function to register 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 register_my_menus() {
register_nav_menus(
array(
'header-menu' => __( 'Header Menu' )
)
);
}

And this would make two menu options appear, header menu and extra menu -

function register_my_menus() {
register_nav_menus(
array(
'header-menu' => __( 'Header Menu' ),
'extra-menu' => __( 'Extra Menu' ))
);
}

Then you need to ensure that the theme turns these menu options on, so you need this bit of code as well -

add_action( 'init', 'register_my_menus' );

The above tells the theme to run your "register_my_menus" procedure. As you can see, your new function makes use of the WordPress register_nav_menus functionality.

テンプレートファイルに場所を追加

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 points 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 version that you see in the admin page.)

To complete the code, you can put your extra menu someplace else. Maybe you want a menu on one of your pages, 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 Page 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 work with that in CSS.

メニューパネルに戻る

That's all the background work. To finish, you would simply visit the Appearance -> Menus panel in your site admin. Now, instead of seeing some text suggesting that your theme doesn't natively support menus, you'll see some Theme Location options.

You can now use the GUI menu creator on this admin panel to put your menu(s) together. Give them each a name, and then assign a menu to a location with the pull-down options.

関連情報

There's a reasonable tutorial on this here which has some more detail around the options available.

ナビゲーションメニュー: register_nav_menus(), register_nav_menu(), unregister_nav_menu() /en , has_nav_menu(), wp_nav_menu(), wp_get_nav_menu_items()

最新英語版: WordPress Codex » Navigation Menus最新版との差分


関数リファレンステンプレートタグ目次もご覧ください。