MENU

wp_list_pages

リンクとしWordPressのページリストを表示します。頻繁にサイドバーやヘッダーをカスタマイズするために使用されますが、同様に他のテンプレートで使用することも出来ます。

Displays a list of WordPress Pages as links. It is often used to customize the Sidebar or Header, but may be used in other Templates as well.

目次

wp_list_pagesのファンクションタグ使用方法

[php] [/php]

概要

[php] 0,
‘show_date’=> ”,
‘date_format’ => get_option(‘date_format’),
‘child_of’ => 0,
‘exclude’ => ”,
‘include’ => ”,
‘title_li’ => __(‘Pages’),
‘echo’ => 1,
‘authors’ => ”,
‘sort_column’ => ‘menu_order, post_title’,
‘link_before’ => ”,
‘link_after’ => ”,
‘walker’ => ” ); ?>[/php]

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

By default, the usage shows:

  • 全てのページとサブページが表示されます(深さの制限はありません)。
  • 作成された日付が表示されません。
  • child_ofの任意のページに限定されるものではありません。
  • 存在しないページは除外します。
  • 存在しないページは明示的に含みます。
  • リスト化されているページのタイトルは”ページ”です。
  • 結果はエコーされます(表示)
  • 任意の特定の著者に限定しません。
  • ページ順序でソートされたページのタイトル
  • 昇順でソート
  • ページは種類によってインデントされた階層化内に表示されます(上記のデフォルトには表示されません)。
  • 全てのページを含みます。(上記のデフォルトには表示されません)
  • 特定のメタキー/メタ値を持つページに制限されません(上記のデフォルトには表示されません)。
  • 親/子がないツリーは除外します。
  • All Pages and sub-pages are displayed (no depth restriction)
  • Date created is not displayed
  • Is not restricted to the child_of any Page
  • No pages are excluded
  • No pages are explicitly included
  • The title of the pages listed is “Pages”
  • Results are echoed (displayed)
  • Is not restricted to any specific author
  • Sorted by Page Order then Page Title.
  • Sorted in ascending order
  • Pages displayed in a hierarchical indented fashion (not shown in defaults above)
  • Includes all Pages (not shown in defaults above)
  • Not restricted to Pages with specific meta key/meta value (not shown in defaults above)
  • No Parent/Child trees excluded

wp_list_pagesのパラメーター

sort_column

(string) 様々な方法のナンバーでページのリストをソートします。デフォルトの設定はページタイトルによってアルファベット順にソートします。

(string) Sorts the list of Pages in a number of different ways. The default setting is sort alphabetically by Page title.

  • ‘post_title’ – (タイトルで)アルファベット順にページをソートーデフォルト
  • ‘menu_order’ – ページ順によってページをソートします。ページ順とページIDとの違いに注意してください。ページIDはWordPressの全ての投稿家ページによって割り当てられたユニークナンバーです。ページ順はページ内のユーザーによって設定することができます。→編集パネル。下記の例を参照してください。
  • ‘post_date’ – 作成時間によってソートします。
  • ‘post_modified’ – 最終更新時間によってソートします。
  • ‘ID’ – 数値のページIDによってソートします。
  • ‘post_author’ – ページの著者の数値IDによってソートします。
  • ‘post_name’ – 投稿スラッグによってアルファベット順にソートします。
  • ‘post_title’ – Sort Pages alphabetically (by title) – default
  • ‘menu_order’ – Sort Pages by Page Order. Note the difference 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 Pages→Edit panel. See the example below.
  • ‘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.

注:sort_columnパラメーターは、WordPressのデーターベースのwp_postテーブル内に任意のフィールドの記述子によってページのリストを並び替えるために使用することができます。幾つかの有効な例はここにリストされています。

Note: 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.

sort_order

(string) ページのリストのソート順(昇順または降順)を変更します。デフォルトは、昇順です。有効な値:

(string) Change the sort order of the list of Pages (either ascending or descending). The default is ascending. Valid values:

  • ‘ASC’ – 最下位から最上位(デフォルト)にソートします。
  • ‘DESC’ – 最上位から最下位にソートします。
  • ‘ASC’ – Sort from lowest to highest (Default).
  • ‘DESC’ – Sort from highest to lowest.

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.)

include

(string) wp_list_pagesによって生成されたリストで特定のページが含まれているのみです。除外するように、このパラメーターは、ページIDのカンマ区切りのリストで指定します。デフォルト値はありません。下記の例のリストにページをインクルードを参照してください。

(string) Only include certain Pages in the list generated by wp_list_pages. Like exclude, this parameter takes a comma-separated list of Page IDs. There is no default value. See the Include Pages in List example below.

depth

(integer) このパラメーターは、wp_list_pagesによって生成されたリストに含まれているページの階層にあるいくつかの多くのレベルを制御します。デフォルト値は0です(全てのページ、全てのサブページをインクルードして表示します)。

(integer) This parameter controls how many levels in the hierarchy of pages are to be included in the list generated by wp_list_pages. The default value is 0 (display all pages, including all sub-pages).

  • 0(デフォルト)任意の深さでページを表示し、ネストされたリストに階層で配置します。
  • −1 任意の深さでページを表示し、フラットリストでシングル内にそれらを配置します。
  • 1 トップレベルのページのみ表示します。
  • 2,3 …与えられた深さでページを表示します。
  • 0 (default) Displays pages at any depth and arranges them hierarchically in nested lists
  • -1 Displays pages at any depth and arranges them in a single, flat list
  • 1 Displays top-level Pages only
  • 2, 3 … Displays Pages to the given depth

child_of

(integer) シングルページのみのサブページを表示します;値としてページのIDを使用します。child_ofパラメーターは指定されたIDの”grandchildren”だけでなく、直接の子孫も取得することに注意してください。0がデフォルトになります(全てのページが表示されます)。

(integer) Displays the sub-pages of a single Page only; uses the ID for a Page as the value. Note that the child_of parameter will also fetch “grandchildren” of the given ID, not just direct descendants. Defaults to 0 (displays all Pages).

show_date

(string) 各ページの次に作成または最終更新日時にを表示します。デフォルト値はnull値です(日時を表示しません)。有効な値:

(string) Display creation or last modified date next to each Page. The default value is the null value (do not display dates). Valid values:

  • ” – 日時を表示しません (デフォルト)。
  • ‘modified’ – 最終更新日時を表示します。
  • ‘xxx’ – 更新されたほかの任意の値より、最初に作成した日時(post_date)のページを表示します。下記の例を参照してください。
  • ” – Display no date (Default).
  • ‘modified’ – Display the date last modified.
  • ‘xxx’ – Any value other than modified displays the date (post_date) the Page was first created. See the example below.

date_format

(string) show_dateパラメーター(例: “l, F j, Y”)によって設定されたページの日時の形式を制御します。このパラメーターのデフォルトはWordPressのオプション内で構成された日時形式です。PHPのWEBサイト上で日時と時間と日時形式ページのフォーマットを参照してください。

(string) Controls the format of the Page date set by the show_date parameter (example: “l, F j, Y”). This parameter defaults to the date format configured in your WordPress options. See Formatting Date and Time and the date format page on the php web site.

title_li

ページリストの見出しのテキストとスタイルを設定します。”Pages”と表示されている ‘__(‘Pages’)’がデフォルトです(the __(”)がローカライズの目的で使用されています)。nullまたは空値(”)を渡す場合、見出しは表示されず、リストは

    ,

タグで囲まないでしょう。見出しの例を参照してください。

(string) Set the text and style of the Page list’s heading. Defaults to ‘__(‘Pages’)’, which displays “Pages” (the __(”) is used for localization purposes). If passed a null or empty value (”), no heading is displayed, and the list will not be wrapped with

    ,

tags. See the example for Headings.

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:

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

meta_key

(string) このカスタムフィールドキーを持っているページのみ含みます(meta_valueフィールドと組み合わせて使用します)。

(string) Only include the Pages that have this Custom Field Key (use in conjunction with the meta_value field).

meta_value

(string) このカスタムフィールド値をもつページのみを含みます(meta_keyフィールドと組み合わせて使用します)。

(string) Only include the Pages that have this Custom Field Value (use in conjunction with the meta_key field).

link_before

(string) タグ内のリンクテキストの前にあるテキストまたはhtmlを設定します。(このパラメータはバージョン2.7で追加されました)

(string) Sets the text or html that precedes the link text inside tag. (This parameter was added with Version 2.7)

link_after

(string) タグ内のリンクテキストを後にあるテキストまたはHTMLを設定します。(このパラメータはバージョン2.7で追加されました)

(string) Sets the text or html that follows the link text inside tag. (This parameter was added with Version 2.7)

authors

(string) この著者IDのカンマで区切られたリストに著者によって書かれたページのみ含みます。著者が指定されていない場合、全ての著者が含まれます。

(string) Only include Pages authored by the authors in this comma-separated list of author IDs. If no authors are specified, all authors are included.

number

(integer) 表示するためのページ数を設定します。これはSQL LIMIT値が定義されたケースです。デフォルトでは、LIMITがありません。(このパラメーターはバージョン2.8で追加されました)注:これは現在動作しません。http://core.trac.wordpress.org/ticket/10745を参照してください。

(integer) Sets the number of Pages to display. This causes the SQL LIMIT value to be defined. Default to no LIMIT. (This parameter was added with Version 2.8) NOTE: this is currently not working, see http://core.trac.wordpress.org/ticket/10745

offset

(integer) ページの設定を収集する前に渡すための(あるいは置換する)ページナンバーです。デフォルトはオフセットがありません。(このパラメーターはバージョン2.8で追加されました。)

(integer) The number of Pages to pass over (or displace) before collecting the set of Pages. Default is no OFFSET. (This parameter was added with Version 2.8)

リストの見出しを非表示または変更する方法

wp_list_pages によって生成されたページの(“Pages”)リストのデフォルトの見出しは、title_liパラメーターにnullまたは空の値を渡すことによって非表示にすることができます。次の例は、リスト上に見出しテキストを表示しません。

The default heading of the list (“Pages”) of Pages generated by wp_list_pages can be hidden by passing a null or empty value to the title_li parameter. The following example displays no heading text above the list.

[php]
[/php]

次の例では、ID9,5及び23であるページのみリストに含まれており、見出しテキストが

の見出しスタイルで “Poetry”という単語に変更されます。

In the following example, only Pages with IDs 9, 5, and 23 are included in the list and the heading text has been changed to the word “Poetry”, with a heading style of

:

[php]
    ‘ . __(‘Poetry’) . ‘

‘ ); ?> [/php]

ページ順でページをリスト表示する方法

次の例では、ページ内で各ページの順序設定によって定義された順序内でページをリスト表示します。→編集パネル

The following example lists the Pages in the order defined by the Order setting for each Page in the Pages→Edit panel.

[php]
[/php]

ページの順序でリストを表示し、サイドバー上に見出し(h2スタイル内)リストとして”Prose”単語を表示したい場合、sidebar.phpファイルに次のコードを追加します。

If you wanted to sort the list by Page Order and display the word “Prose” as the list heading (in h2 style) on a Sidebar, you could add the following code to the sidebar.php file:

[php]
    ‘ . __(‘Prose’) . ‘

    ‘ ); ?>

[/php]

以下のコードを使用して、ページはページ順序に見出しなしで表示します。

Using the following piece of code, the Pages will display without heading and in Page Order:

[php]
[/php]

投稿日時によってページをソート剃る方法

この例では、ページは(作成された)日時によってソートされ、各ページリスト項目に次の日時を表示します。

This example displays Pages sorted by (creation) date, and shows the date next to each Page list item.

[php]
[/php]

リストからページを除外する方法

wp_list_pagesによって生成されるリストから特定のページを非表示するには、excludeパラメーターを使用してください。

Use the exclude parameter to hide certain Pages from the list to be generated by wp_list_pages.

[php]
[/php]

リスト内にあるページを含める方法

リスト内の唯一の特定ページを含めるには、例えばID番号35, 7, 26 及び 13のページなど、インクルードパラメーターを使用してください。

To include only certain Pages in the list, for instance, Pages with ID numbers 35, 7, 26 and 13, use the include parameter.

[php]
    ‘ . __(‘Pages’) . ‘

    ‘ ); ?>

[/php]

サブページをリスト表示する方法

前のWordpressの2.0.1へのバージョン:

Versions prior to WordPress 2.0.1 :

the_content()後にWordPress テーマのpage.phpテンプレートのthe_post() セクションを内部においてください。または、サブページを持ちページに対して使用するpage.phpテンプレートにコピーして置いてください。

Put this inside the the_post() section of the page.php template of your WordPress theme after the_content(), or put it in a copy of the page.php template that you use for pages that have sub-pages:

[php]
[/php]

この例は、ページテンプレート内に配置された場合、グローバル$idは設定されていないので、Wordpress 2.0.1あるいはそれ以降では動作しません。代わりに次のコードを使用します。

This example does not work with WordPress 2.0.1 or newer if placed in a page template because the global $id is not set. Use the following code instead.

WordPressの2.0.1またはそれ以降:

WordPress 2.0.1 or newer :

注:サブページがないばあいでもHTMLタグ(あるいは

      いずれか)が必要です。リストスタイルにCSSを使用する場合、そのことに留意してください。

      NOTE: Requires an HTML tag (either

        or

          ) even if there are no subpages. Keep this in mind if you are using css to style the list.

      [php]
        ID.’&show_date=modified
        &date_format=$date_format’); ?>
      [/php]

      次の例は、現在のページに子(親として現在のページを指定するページ)がある場合、リストのみ生成します。

      The following example will generate a list only if there are child (Pages that designate the current page as a Parent) for the current Page:

      [php]ID.’&echo=0′);
      if ($children) { ?>

      [/php]

      サブページ上の場合でさえサブページをリスト表示する方法

      上記の例では、親ページから子を表示するのみになるが、実際に子ページ上になります。このコードは親あるいは1つの子上である時に、子ページ及び子ページのみ表示されます。

      The above examples will only show the children from the parent page, but not when actually on a child page. This code will show the child pages, and only the child pages, when on a parent or on one of the children.

      サイドバーにウィジェットブロックの後に配置している場合、このコードは動作しません。

      This code will not work if placed after a widget block in the sidebar.

      [php]post_parent)
      $children = wp_list_pages(“title_li=&child_of=”.$post->post_parent.”&echo=0″);
      else
      $children = wp_list_pages(“title_li=&child_of=”.$post->ID.”&echo=0″);
      if ($children) { ?>

      [/php]

      別の方法として、sidebar.phpにこのコードは、トップレベルページのみ表示しますが、子(あるいは子)を持つページを表示する時、親である子のみ表示します。

      As an alternative, this code in a sidebar.php, displays only top level Pages, but when viewing a Page that has children (or is a child) it displays only children of that parent.

      • メインページを訪問する時、全てのトップレベルページがサイドバーにリスト表示されます。
      • 子を持たないトップレベルページを訪問する時、全てのトップレベルページがリスト表示されます。
      • 子、まさに子ページ、子孫ページとトップレベルのページを訪問する時、表示されます。
      • 親の子ページ、まさに子と子孫ページを訪問する時、表示されます。
      • When visiting main page, all top level pages are listed in the sidebar.
      • When visiting a top level page with no children, all top level pages are listed.
      • When visiting a top level page with children, just the children pages, and descendant pages, are listed.
      • When visiting a child page, just the children, and descendant pages, of that parent, are listed.
      [php]Top Level Pages

      ‘ );
      if (is_page( )) {
      $page = $post->ID;
      if ($post->post_parent) {
      $page = $post->post_parent;
      }
      $children=wp_list_pages( ‘echo=0&child_of=’ . $page . ‘&title_li=’ );
      if ($children) {
      $output = wp_list_pages (‘echo=0&child_of=’ . $page . ‘&title_li=

      Child Pages

      ‘);
      }
      }
      echo $output;
      ?>[/php]

      そのページリスト:子(サブ)ページが存在する場合、親ページと子ページ上のサブページのリストページを表示します。しかしこのコードは前の例から異なるマークするタイトルに親ページ名を保持します。

      Page List that: Only displays if child (sub) pages exist, displays page list of subpages on the parent page AND on the child pages HOWEVER this code keeps the parent page name in the title which makes it different from the previous example.)

      < ?php if($post->post_parent) {
      $children = wp_list_pages(“title_li=&child_of=”.$post->post_parent.”&echo=0″);
      $titlenamer = get_the_title($post->post_parent);
      }

      else {
      $children = wp_list_pages(“title_li=&child_of=”.$post->ID.”&echo=0″);
      $titlenamer = get_the_title($post->ID);
      }
      if ($children) { ?>

      < ?php echo $titlenamer; ?>

        < ?php echo $children; ?>

      < ?php } ?>

      全体のサブページを表示する方法

      これは全体のサブページリストを取得する方法です。

      This is how to get the whole subpages list

      [php]post_parent){
      // このトップレベルページのサブページを表示します。will display the subpages of this top level page
      $children = wp_list_pages(“title_li=&child_of=”.$post->ID.”&echo=0″);
      }else{
      // 親レベルのサブページのみ表示します。diplays only the subpages of parent level
      //$children = wp_list_pages(“title_li=&child_of=”.$post->post_parent.”&echo=0″);

      if($post->ancestors)
      {
      // 今、このページのトップIDを付与することができます。now you can get the the top ID of this page
      // wp is putting the ids DESC, thats why the top level ID is the last one
      $ancestors = end($post->ancestors);
      $children = wp_list_pages(“title_li=&child_of=”.$ancestors.”&echo=0″);
      // 常に全体のサブページのリストが表示されます。you will always get the whole subpages list
      }
      }

      if ($children) { ?>

      [/php]

      ページ項目のマークアップとスタイリングする方法

      デフォルトでは、書き込み>ページの管理者パネルで作成されたWordPressページのページを順不同リストで、入れ子を生成します。title_liに空の文字列を設定することによって最も外側の項目 (li.pagenav)とリスト (ul)を削除することができます。

      By default, wp_list_pages() generates a nested, unordered list of WordPress Pages created with the Write > Page admin panel. You can remove the outermost item (li.pagenav) and list (ul) by setting the title_li parameter to an empty string.

      wp_list_pages()によって生成された全てのリスト項目(li)は、クラスのpage_itemが付与されています。wp_list_pages()がページを表示している間に呼び出される時、項目リストにページは追加クラスのcurrent_page_itemを与えられます。

      All list items (li) generated by wp_list_pages() are marked with the class page_item. When wp_list_pages() is called while displaying a Page, the list item for that Page is given the additional class current_page_item.

      [php] [/php]

      CSSセレクタでスタイルを設定することができます。

      They can be styled with CSS selectors:

      [php].pagenav { … } /* 最も外側のリスト項目:リスト全体が含まれます。the outermost list item; contains whole list */
      .page-item-2 { … } /* ページID2のための項目。item for Page ID 2 */
      .page_item { … } /* 任意のページ項目。any Page item */
      .current_page_item { … } /* 現在のページ。the current Page */
      .current_page_parent { … } /* 現在のページの親。parent of the current Page */
      .current_page_ancestor { … } /* 現在のページの任意の祖先。any ancestor of the current Page */
      [/php]

      インスタンスのためのアコーディオンメニューの効果を有効にするために、以下のCSSを使用することができます。

      In order to achieve an accordion menu effect for instance, the following CSS can be used:

      [php].pagenav ul ul,
      .pagenav .current_page_item ul ul,
      .pagenav .current_page_ancestor ul ul,
      .pagenav .current_page_ancestor .current_page_item ul ul,
      .pagenav .current_page_ancestor .current_page_ancestor ul ul {
      display: none;
      }

      .pagenav .current_page_item ul,
      .pagenav .current_page_ancestor ul,
      .pagenav .current_page_ancestor .current_page_item ul,
      .pagenav .current_page_ancestor .current_page_ancestor ul,
      .pagenav .current_page_ancestor .current_page_ancestor .current_page_item ul,
      .pagenav .current_page_ancestor .current_page_ancestor .current_page_ancestor ul {
      display: block;
      }[/php]

      親ページと全ての子孫ページをリスト表示する方法

      特定の親ツリー(親と全ての世代を表示します)を表示するためにwp_list_pagesを指示する方法がありません。
      この例は親のための全ての子孫を取得するためにget_pagesを使用します。その際’family tree’を表示するためにwp_list_pagesを使用してください。

      Since there’s no way to tell wp_list_pages to display a particular parent tree (parent and all generations displayes) this example uses get_pages to get all the descendants for a parent, then use wp_list_pages to display the ‘family tree’.

      [php] $parent
      );
      $pages = get_pages($args);
      if ($pages) {
      $pageids = array();
      foreach ($pages as $page) {
      $pageids[]= $page->ID;
      }

      $args=array(
      ‘title_li’ => ‘Tree of Parent Page ‘ . $parent,
      ‘include’ => $parent . ‘,’ . implode(“,”, $pageids)
      );
      wp_list_pages($args);
      }
      ?>[/php]

      現在のページ、現在のページの祖先、そして現在のページの子をリスト表示し、child_ofが全ての子を表示するようになって以来、wpdbは全ての’and the kitchen sink’を表示しないように含めるのと同様に代わりに使用されます。

      List current Page, ancestors of current page, and children of current page
      Since child_of displays all children, wpdb is used instead, along with include to not display everything ‘and the kitchen sink’.

      [php]post_parent){
      //祖先のページを収集します。collect ancestor pages
      $relations = get_post_ancestors($post->ID);
      //子ページを取得します。get child pages
      $result = $wpdb->get_results( “SELECT ID FROM wp_posts WHERE post_parent = $post->ID AND post_type=’page'” );
      if ($result){
      foreach($result as $pageID){
      array_push($relations, $pageID->ID);
      }
      }
      //現在の投稿とページを追加します。add current post to pages
      array_push($relations, $post->ID);
      //子と親と地震のカンマ区切りのリストを取得します。get comma delimited list of children and parents and self
      $relations_string = implode(“,”,$relations);
      //収集したページのみリストに含めて使用します。use include to list only the collected pages.
      $sidelinks = wp_list_pages(“title_li=&echo=0&include=”.$relations_string);
      }else{
      // メインレベルと子のみ表示します。display only main level and children
      $sidelinks = wp_list_pages(“title_li=&echo=0&depth=1&child_of=”.$post->ID);
      }

      if ($sidelinks) { ?>

        タグにリンクする。links in

      • tags
        echo $sidelinks; ?>

      [/php]

      ホームページの一覧を表示する方法

      ブログページへのリンクをしたい場合は、同様にwp_page_menu()を使用してください。

      If you want a link to the blog page as well use wp_page_menu().

      カスタムポストタイプのメンバーをリスト化する方法

      特定のカスタム投稿タイプが事実上階層である場合、wp_list_pages()はカスタム投稿タイプのメンバーを一覧表示することに使用することができます。この例ではカスタム投稿タイプのポートフォリオがリスト表示されています。

      If a given custom post type is hierarchical in nature, then wp_list_pages() can be used to list the member of that custom post type. In this example the custom post type Portfolio is listed:

      [php]‘portfolio’,
      ‘title_li’=> __(‘Portfolio’)
      );
      wp_list_pages( $args );
      ?> [/php]

      最上位の祖先とその直下の子を一覧表示する方法

      このメソッドは、最上位の祖先の直下の子と同様に現在のページの最上位祖先を表示します。これはクリーンな第2のサブナビゲーションに使用することができます。

      最初に、次の関数をを作成します(できればのfunctions.php内に、これがテーマにあると仮定して)。

      This method will show the topmost ancestor of the current page as well as the topmost ancestor’s immediate children. This can be used for clean secondary subnavigation.

      First, create the following function (preferably in functions.php, assuming this is for a theme):

      [php]if(!function_exists(‘get_post_top_ancestor_id’)){
      /**
      * Gets the id of the topmost ancestor of the current page. Returns the current
      * page’s id if there is no parent.
      *
      * @uses object $post
      * @return int
      */
      function get_post_top_ancestor_id(){
      global $post;

      if($post->post_parent){
      $ancestors = array_reverse(get_post_ancestors($post->ID));
      return $ancestors[0];
      }

      return $post->ID;
      }}[/php]

      次に、あなたのテーマに次のコードを追加します(あなたがメニューが表示したい場所):

      Next, add the following code to your theme (wherever you want the menu to appear):

      [php]
        ”,’include’=>get_post_top_ancestor_id()) ); ?>
        ”,’depth’=>1,’child_of’=>get_post_top_ancestor_id()) ); ?>
      [/php]

      注釈

      参照: wp_page_menu(), get_pages()

      変更ログ

      • Since: 1.5.0
      • 2.7 : Added the link_before, link_after and exclude_tree parameters.
      • 2.8 : Added the number and offset parameters.

      ソースファイル

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

      wp_list_pages() 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()

よかったらシェアしてね!
  • URLをコピーしました!

この記事を書いた人

WordPress Love! 休日はほぼWordPress仲間と一緒に勉強会や写真を撮りに行っています。現在育児中のため、オフが多いです(>△<<<)

コメント

コメントする

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください

目次