wp_list_pages

Sponsored Link

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

Sponsored Link

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 wp_list_pages( $args ); ?> 

概要

<?php $args = array(
	'depth'=> 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'   => '' ); ?>

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

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.

<ul>
<?php wp_list_pages('title_li='); ?>
</ul>

次の例では、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

:

<ul>
 <?php wp_list_pages('include=5,9,23&amp;title_li=<h2>' . __('Poetry') . '</h2>' ); ?>
</ul>

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

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

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

<ul>
 <?php wp_list_pages('sort_column=menu_order'); ?>
</ul>

ページの順序でリストを表示し、サイドバー上に見出し(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:

<ul>
 <?php wp_list_pages('sort_column=menu_order&amp;title_li=<h2>' . __('Prose') . '</h2>' ); ?>
</ul>

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

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

<ul>
 <?php wp_list_pages('sort_column=menu_order&amp;title_li='); ?>
</ul>

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

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

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

<ul>
 <?php wp_list_pages('sort_column=post_date&amp;show_date=created'); ?>
</ul>

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

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

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

<ul>
 <?php wp_list_pages('exclude=17,38' ); ?>
</ul>

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

リスト内の唯一の特定ページを含めるには、例えば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.

<ul>
 <?php wp_list_pages('include=7,13,26,35&amp;title_li=<h2>' . __('Pages') . '</h2>' ); ?>
</ul>

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

前の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:

<ul>
 <?php
  global $id;
  wp_list_pages("title_li=&amp;child_of=$id&amp;show_date=modified
  &amp;date_format=$date_format"); ?>
</ul>

この例は、ページテンプレート内に配置された場合、グローバル$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タグ(あるいは