wp_page_menu

Sponsored Link

WordPressのページのリンクとしての一覧を表示します。ホームに自動的にページのリストを追加することで表示する良い機会を提供します。このタグは、サイドバーやヘッダをカスタマイズすると便利ですが、同様に他のテンプレートで使用することができます。

Sponsored Link

Displays a list of WordPress Pages as links, and affords the opportunity to have Home added automatically to the list of Pages displayed. This Tag is useful to customize the Sidebar or Header, but may be used in other Templates as well.

wp_page_menuのテンプレートタグ使用方法

<?php wp_page_menu( $args ); ?> 

デフォルトの使い方

<?php $args = array(
	'sort_column' => 'menu_order, post_title',
	'menu_class'  => 'menu',
	'include'     => '',
	'exclude'     => '',
	'echo'        => true,
	'show_home'   => false,
	'link_before' => '',
	'link_after'  => '' ); ?>

デフォルトでの使い方を表示:

  • メニューの順序とタイトルによってソートされます
  • divのclassは’menu’です。
  • ページがない場合は除外します。
  • ページが明示的にインクルードされます。
  • 結果はエコーされます。(echo で表示される)
  • link_beforeがない。あるいは、link_afterがテキスト。
  • “Home”のページのリストに追加しないでください
  • 注:出力は、

    タグに囲まれます。

By default, the usage shows:

* Sorted by menu order and title
* The div class is ‘menu’
* No pages are excluded
* No pages are explicitly included
* Results are echoed (displayed)
* No link_before or link_after text
* Do not add “Home” to the list of pages
* Note: Output is encompassed by the

    and

tags

wp_page_menuのパラメーター

sort_column

(string)ページのタイトルによってアルファベット順にページのリストをソートします。デフォルトの設定は、メニューの順序とページのタイトルのアルファベット順にソートします。 sort_columnパラメーターは、WordPressのデータベースのwp_postテーブルの中の任意のフィールドの記述子によって、ページのリストをソートするために使用する事が出来ます。いくつかの有用な例がここに表示します。

  • ‘post_title’ – タイトルのアルファベット順によってページがソートされる。
  • ‘menu_order’ – ページ順によってページがソートされる。違いに注意

(string) Sorts the list of Pages in a alphabetic order by title of the pages. The default setting is sort by menu order and alphabetically by page title. The sort_column parameter can be used to sort the list of Pages by the descriptor of any field in the wp_post table of the WordPress database. Some useful examples are listed here.

* ‘post_title’ – Sort Pages alphabetically by title.
* ‘menu_order’ – Sort Pages by Page Order. Note the difference

ページ順序とページIDの間。ページIDは、WordPressの全ての投稿かページによってユニークナンバーが割り当てられています。ページ順序は、管理者画面(管理>ページ>編集)でユーザーによって設定する事が出来ます。

  • ‘post_date’ – 作成時間によってソート。
  • ‘post_modified – 最終更新時間によってソート。
  • ‘ID’ – 数値のページIDによってソート。
  • ‘post_author’ – ページ著者の数値IDによってソート。
  • ‘post_name’ -投稿スラッグのアルファベット順によってソート。

between Page Order and Page ID. The Page ID is a unique number assigned by WordPress to every post or page. The Page Order can be set by the user in the administrative panel (e.g. Administration > Page > Edit).
* ‘post_date’ – Sort by creation time.
* ‘post_modified’ – Sort by time last modified.
* ‘ID’ – Sort by numeric Page ID.
* ‘post_author’ – Sort by the Page author’s numeric ID.
* ‘post_name’ – Sort alphabetically by Post slug.

menu_class

(string)divクラスはリストに表示します。デフォルトはmenuです。

(string) The div class the list is displayed in. Defaults to menu.

include

(string)IDと一致したページの一覧表のみ識別します。すなわち、wp_page_menu(‘include=2,14’)は、idの2と14のページのみリストアップします。

(string) Only list pages identified with the corresponding id’s, i.e. wp_page_menu(‘include=2,14’) will list only pages with id’s 2 and 14

exclude

(string)ページIDがカンマ区切りで定義されたリストは、リストから除外します(例: ‘exclude=3,7,31’)。デフォルト値はありません下記のリスト例から除外ページを参照してください。

(string) Define a comma-separated list of Page IDs to be excluded from the list (example: ‘exclude=3,7,31’). There is no default value. See the Exclude Pages from List example below.

exclude_tree

(string)親ページIDがカンマ区切りで定義されたリストはを除外します。
親と親の子ページ全てを除外するためにこのパラメーターを使ってください。
‘exclude_tree=5’は、親ページ5とその子(すべての子孫)ページを除外するでしょう。
(このパラメーターはバージョン2.7で追加され、それはバージョン2.8.1で記載されているように機能しません。 – バグレポートを参照してください。)

(string) Define a comma-separated list of parent Page IDs to be excluded. Use this parameter to exclude a parent and all of that parent’s child Pages. So ‘exclude_tree=5’ would exclude the parent Page 5, and its child (all descendant) Pages. (This parameter was added with Version 2.7, and it does not function as described as of version 2.8.1 – See bug report.)

echo

(boolean) リンクを生成されたリストの表示として切り替えます。または、PHPで使うためにHTMLテキストの文字列としてリストを返します。デフォルト値は1です(生成されたリストの項目を表示します)。有効な値:

(boolean) Toggles the display of the generated list of links or return the list as an HTML text string to be used in PHP. The default value is 1 (Display the generated list items). Valid values:

  • 0 (False)
  • 1 (True) – default

show_home

(boolean)”Pages”のリストに最初の項目として”Home”を追加します。
“Home”に割り当てられるURLは、管理>設定>一般のブログのアドレス(URL)から取り出されます。デフォルト値は0です(生成されたリスト内に”Home”が表示されません)。有効な値:

  • 0 (False) – default
  • 1 (True)
  • – “ホーム”の代わりにリンクとしてこのテキストを使用します(show_home はまだ本当の考えられている)。

(boolean) Add “Home” as the first item in the list of “Pages”. The URL assigned to “Home” is pulled from the Blog address (URL) in Administration > Settings > General. The default value is 0 (do NOT display “Home” in the generated list). Valid values:

* 0 (False) – default
* 1 (True)
* – Use this text as the link in place of “Home” (show_home is still considered true)

link_before

(string) Sets the text or html that proceeds the link text inside tag.

link_after

(string)次のの内部リンクのテキストをテキストかHTMLに設定します。

(string) Sets the text or html that follows the link text inside tag.

ページとしてホームを表示する方法

次の例では、表示されたページの先頭に追加する”Home”のケースです。また、ページがdiv要素で囲まれたページID5,9,23は、表示したページのリストから除外して、ページはページ順でリストアップします。このリストは、”Page Menu”タイトルとして始まります。

The following example causes “Home” to be added to the beginning of the list of Pages displayed. In addition, the Pages wrapped in a div element, Page IDs 5, 9, and 23, are excluded from the list of Pages displayed, and the pages are listed in Page Order. The list is prefaced with the title, “Page Menu”,

<h2>Page Menu</h2>
<?php wp_page_menu('show_home=1&amp;exclude=5,9,23&amp;menu_class=page-navi&amp;sort_column=menu_order'); ?>

ページのようにHOMEをブログを呼び出して表示する方法Display Home as a Page called Blog

次の例では、ページのリストの先頭に追加する”Blog” (“Home”として代わりに)を表示するケースです。

The following example causes “Blog” (instead of “Home”) to be added to the beginning of the list of Pages displayed:

<?php wp_page_menu( array( 'show_home' => 'Blog', 'sort_column' => 'menu_order' ) ); ?>

Homeのみ表示する方法

次の例は、”Home”のリンクだけ表示します。ホームに表示されているリンクが存在しないinclude=99999’の参照ページIDに注意してください。

The following example displays just a link to “Home”. Note that the include=9999′ references a Page ID that does not exist so only a link for Home is displayed.

<?php wp_page_menu('show_home=1&amp;include=9999'); ?>

備考

参照: wp_list_pages()

変更ログ

  • Since: 2.7.0
  • 2.8.1 : sort_columnパラメータのデフォルト値は’post_title’から’menu_order, post_title’に変更。sort_column parameter default changed from ‘post_title’ to ‘menu_order, post_title’.

ソースファイル

wp_page_menu()は、wp-includes/post-template.php内に位置しています。

wp_page_menu() is located in wp-includes/post-template.php.

関連テンプレートタグ

wp_list_authors, wp_list_categories, wp_list_pages, wp_list_bookmarks, wp_list_comments, wp_get_archives, wp_page_menu, wp_dropdown_pages, wp_dropdown_categories, wp_dropdown_users

Sponsored Link