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

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

「テンプレートタグ/wp list pages」の版間の差分

提供: WordPress Codex 日本語版
移動先: 案内検索
(en:Template Tags/wp_list_pages 2007年12月14日 (金) 19:06 Kchrist 版)
 
(未翻訳テンプレ追加、体裁微調整)
1行目: 1行目:
== Description ==
+
{{NeedTrans}}
The Template Tag, '''wp_list_pages()''', displays a list of WordPress [[Pages]] as links. It is often used to customize the [[Customizing_Your_Sidebar|Sidebar]] or [[Designing_Headers|Header]], but may be used in other [[Templates]] as well.
+
  
This [[Template Tags|Template Tag]] is available for WordPress versions 1.5 and newer.
+
<div id="Description">
 +
== 説明 ==
 +
</div>
 +
The Template Tag, '''wp_list_pages()''', displays a list of WordPress [[Pages]] as links. It is often used to customize the [[:en:Customizing_Your_Sidebar|Sidebar]] or [[:en:Designing_Headers|Header]], but may be used in other [[テンプレート|Templates]] as well.
  
== Usage ==
+
This [[テンプレートタグ|Template Tag]] is available for WordPress versions 1.5 and newer.
%%% <?php wp_list_pages('arguments'); ?> %%%
+
  
== Examples ==
+
<div id="Usage">
 +
== 使い方 ==
 +
</div>
 +
<?php wp_list_pages('arguments'); ?>
  
===Default Usage===
+
<div id="Examples">
 +
== 用例 ==
 +
</div>
 +
 
 +
<div id="Default_Usage">
 +
=== 初期設定での使用 ===
 +
</div>
 
<pre>
 
<pre>
 
$defaults = array(
 
$defaults = array(
39行目: 49行目:
 
  wp_list_pages();
 
  wp_list_pages();
  
 +
<div id="Hiding_or_Changing_the_List_Heading">
 
=== Hiding or Changing the List Heading ===
 
=== Hiding or Changing the List Heading ===
 +
</div>
 
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.
 
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.
  
64行目: 76行目:
 
</div>
 
</div>
  
 +
<div id="List_Pages_by_Page_Order">
 
=== List Pages by Page Order ===
 
=== List Pages by Page Order ===
 +
</div>
 
The following example lists the Pages in the order defined by the '''Page Order''' settings for each Page in the [[Administration_Panels#Write_Page|Write]] > [[Write_Page_SubPanel|Page]] administrative panel.
 
The following example lists the Pages in the order defined by the '''Page Order''' settings for each Page in the [[Administration_Panels#Write_Page|Write]] > [[Write_Page_SubPanel|Page]] administrative panel.
  
101行目: 115行目:
 
</div>
 
</div>
  
 +
<div id="Sort_Pages_by_Post_Date">
 
=== Sort Pages by Post Date===
 
=== Sort Pages by Post Date===
 +
</div>
 
This example displays Pages sorted by (creation) date, and shows the date next to each Page list item.
 
This example displays Pages sorted by (creation) date, and shows the date next to each Page list item.
  
114行目: 130行目:
 
</div>
 
</div>
  
 +
<div id="Exclude_Pages_from_List">
 
=== Exclude Pages from List ===
 
=== Exclude Pages from List ===
 +
</div>
 
Use the '''exclude''' parameter hide certain Pages from the list to be generated by ''wp_list_pages''. Excluding a Page will also exclude all of its sub-pages from the list to be generated. <!-- '''Note''': Page numbers must be in ascending order (i.e. <tt>'exclude=17,38'</tt> and not <tt>'exclude=38,17'</tt>).  Note this isn't true at least as 2.1.3 -->
 
Use the '''exclude''' parameter hide certain Pages from the list to be generated by ''wp_list_pages''. Excluding a Page will also exclude all of its sub-pages from the list to be generated. <!-- '''Note''': Page numbers must be in ascending order (i.e. <tt>'exclude=17,38'</tt> and not <tt>'exclude=38,17'</tt>).  Note this isn't true at least as 2.1.3 -->
  
127行目: 145行目:
 
</div>
 
</div>
  
 +
<div id="Include_Pages_in_List">
 
=== Include Pages in List ===
 
=== Include Pages in List ===
 +
</div>
 
To include only certain Pages in the list, for instance, Pages with ID numbers 35, 7, 26 and 13, use the '''include''' parameter. <!--'''Note''': Page numbers must be in ascending order (i.e. <tt>'include=7,13,26,35'</tt> and not <tt>'include=35,7,26,13'</tt>).  this does not seem to be true at least at 2.1.3-->
 
To include only certain Pages in the list, for instance, Pages with ID numbers 35, 7, 26 and 13, use the '''include''' parameter. <!--'''Note''': Page numbers must be in ascending order (i.e. <tt>'include=7,13,26,35'</tt> and not <tt>'include=35,7,26,13'</tt>).  this does not seem to be true at least at 2.1.3-->
  
140行目: 160行目:
 
</div>
 
</div>
  
 +
<div id="List_Sub-Pages_.28versions_prior_to_Wordpress_2.0.1.29">
 
=== List Sub-Pages (versions prior to Wordpress 2.0.1)===
 
=== List Sub-Pages (versions prior to Wordpress 2.0.1)===
 +
</div>
 
Put this inside the <tt>the_post()</tt> section of the page.php template of your WordPress theme after <tt>the_content()</tt>, or put it in a copy of the page.php template that you use for pages that have sub-pages:
 
Put this inside the <tt>the_post()</tt> section of the page.php template of your WordPress theme after <tt>the_content()</tt>, or put it in a copy of the page.php template that you use for pages that have sub-pages:
  
161行目: 183行目:
 
<span style="color:#c00;">NOTE: 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</span>
 
<span style="color:#c00;">NOTE: 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</span>
  
 +
<div id="List_Sub-Pages_.28Wordpress_2.0.1_or_newer.29">
 
=== List Sub-Pages (Wordpress 2.0.1 or newer)===
 
=== List Sub-Pages (Wordpress 2.0.1 or newer)===
 +
</div>
 
NOTE: Requires an HTML tag (either <tt><nowiki><ul></nowiki></tt> or <tt><nowiki><ol></nowiki></tt>) even if  there are no subpages. Keep this in mind if you are using css to style the list.
 
NOTE: Requires an HTML tag (either <tt><nowiki><ul></nowiki></tt> or <tt><nowiki><ol></nowiki></tt>) even if  there are no subpages. Keep this in mind if you are using css to style the list.
  
190行目: 214行目:
 
</div>
 
</div>
  
 +
<div id="List_subpages_even_if_on_a_subpage">
 
=== List subpages even if on a subpage ===
 
=== List subpages even if on a subpage ===
 +
</div>
 
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.
 
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.
  
212行目: 238行目:
 
</div>
 
</div>
  
 +
<div id="Markup_and_styling_of_page_items">
 
=== Markup and styling of page items ===
 
=== Markup and styling of page items ===
 +
</div>
  
By default, '''wp_list_pages()''' generates a nested, unordered list of WordPress [[Pages]] created with the [[Administration_Panels#Write_Page|Write]] > [[Write_Page_SubPanel|Page]] admin panel. You can remove the outermost item (<tt>li.pagenav</tt>) and list (<tt>ul</tt>) by setting the <var>title_li</var> parameter to an empty string.
+
By default, '''wp_list_pages()''' generates a nested, unordered list of WordPress [[Pages]] created with the [[管理パネル#Write_Page|Write]] > [[Write_Page_SubPanel|Page]] admin panel. You can remove the outermost item (<tt>li.pagenav</tt>) and list (<tt>ul</tt>) by setting the <var>title_li</var> parameter to an empty string.
  
 
All list items (<tt>li</tt>) generated by '''wp_list_pages()''' are marked with the class <tt>page_item</tt>. When '''wp_list_pages()''' is called while displaying a Page, the list item for that Page is given the additional class <tt>current_page_item</tt>.
 
All list items (<tt>li</tt>) generated by '''wp_list_pages()''' are marked with the class <tt>page_item</tt>. When '''wp_list_pages()''' is called while displaying a Page, the list item for that Page is given the additional class <tt>current_page_item</tt>.
237行目: 265行目:
 
</pre>
 
</pre>
  
They can be styled with [[Glossary#CSS|CSS selectors]]:
+
They can be styled with [[用語集#CSS|CSS selectors]]:
  
 
   .pagenav { ... }
 
   .pagenav { ... }
244行目: 272行目:
 
   .current_page_parent { ... }
 
   .current_page_parent { ... }
  
== Parameters ==
+
<div id="Parameters">
 +
== パラメータ ==
 +
</div>
 
; '''sort_column''' (''string''):Sorts the list of Pages in a number of different ways. The default setting is ''sort alphabetically by Page title''.
 
; '''sort_column''' (''string''):Sorts the list of Pages in a number of different ways. The default setting is ''sort alphabetically by Page title''.
  
253行目: 283行目:
 
:* <tt>'ID'</tt> - Sort by numeric Page ID.
 
:* <tt>'ID'</tt> - Sort by numeric Page ID.
 
:* <tt>'post_author'</tt> - Sort by the Page author's numeric ID.
 
:* <tt>'post_author'</tt> - Sort by the Page author's numeric ID.
:* <tt>'post_name'</tt> - Sort alphabetically by Post [[Glossary#Slug|slug]].
+
:* <tt>'post_name'</tt> - Sort alphabetically by Post [[用語集#Slug|slug]].
 
----
 
----
'''Note:''' The '''sort_column''' parameter can be used to sort the list of Pages by the descriptor of any field in the [[Database Description#Table:_wp_posts|wp_post table]] of the WordPress database. Some useful examples are listed here.  
+
'''Note:''' The '''sort_column''' parameter can be used to sort the list of Pages by the descriptor of any field in the [[データベース概要#Table:_wp_posts|wp_post table]] of the WordPress database. Some useful examples are listed here.  
 
----
 
----
  
294行目: 324行目:
 
; meta_value : (''string'') Only include the Pages that have this Custom Field Value (use in conjuntion with the meta_key field).
 
; meta_value : (''string'') Only include the Pages that have this Custom Field Value (use in conjuntion with the meta_key field).
  
== Related ==
+
<div id="Related">
 +
== 関連 ==
 +
</div>
  
 
{{Tag General Tags}}
 
{{Tag General Tags}}
  
 
{{Query String Tag Footer}}
 
{{Query String Tag Footer}}
 
{{Copyedit}}
 
  
 
{{原文|Template Tags/wp_list_pages|46181}}
 
{{原文|Template Tags/wp_list_pages|46181}}
 +
 +
{{DEFAULTSORT:wp_list_pages}}
  
 
[[en:Template Tags/wp_list_pages]]
 
[[en:Template Tags/wp_list_pages]]

2008年3月30日 (日) 09:51時点における版

このページ「テンプレートタグ/wp list pages」は未翻訳です。和訳や日本語情報を加筆してくださる協力者を求めています

The Template Tag, wp_list_pages(), 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.

This Template Tag is available for WordPress versions 1.5 and newer.

使い方

<?php wp_list_pages('arguments'); ?>

用例

初期設定での使用

$defaults = array(
    'depth'       => 0, 
    'show_date'   => '',
    'date_format' => get_option('date_format'),
    'child_of'    => 0, 
    'exclude'     => '',
    'title_li'    => __('Pages'), 
    'echo'        => 1,
    'authors'     => '',
    'sort_column' => 'menu_order, post_title');

By default, the usage shows:

  • 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
  • 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 (not shown in defaults above)
  • 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)
wp_list_pages();

Hiding or Changing the List Heading

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>

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 <h2>:

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

List Pages by Page Order

The following example lists the Pages in the order defined by the Page Order settings for each Page in the Write > Page administrative panel.

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

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&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&title_li='); ?>
</ul>

Sort Pages by Post Date

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&show_date=created'); ?>
</ul>

Exclude Pages from List

Use the exclude parameter hide certain Pages from the list to be generated by wp_list_pages. Excluding a Page will also exclude all of its sub-pages from the list to be generated.

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

Include Pages in List

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&title_li=<h2>' . __('Pages') . '</h2>' ); ?>
</ul>

List Sub-Pages (versions prior to Wordpress 2.0.1)

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; // teensy bit insane, sorry
$date_format = '<\b\r /><\s\p\a\n '. '\s\t\y\l\e="\f\o\n\t-\s\i\z\e: \s\m\a\l\l\e\r">'. '\l\a\s\t\m\o\d Y-n-j</\s\p\a\n>'; wp_list_pages("title_li=&child_of=$id&show_date=modified
&date_format=$date_format"); ?>
</ul>

NOTE: 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

List Sub-Pages (Wordpress 2.0.1 or newer)

NOTE: Requires an HTML tag (either <ul> or <ol>) even if there are no subpages. Keep this in mind if you are using css to style the list.

<ul>
<?php
wp_list_pages('title_li=&child_of='.$post->ID.'&show_date=modified
&date_format=$date_format'); ?>
</ul>

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
$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
if ($children) { ?>
<ul>
<?php echo $children; ?>
</ul>
<?php } ?>

List subpages even if on a subpage

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.

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


<?php
if($post->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) { ?>
<ul>
<?php echo $children; ?>
</ul>
<?php } ?>

Markup and styling of page items

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.

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.

<li class="pagenav">
  Pages
  <ul>
    <li class="page_item current_page_parent">
      [parent of the current page]
      <ul>
        <li class="page_item current_page_item">
          [the current page]
        </li>
      </ul>
    </li>
    <li class="page_item">
      [another page]
    </li>
  </ul>
</li>

They can be styled with CSS selectors:

 .pagenav { ... }
 .page_item { ... }
 .current_page_item { ... }
 .current_page_parent { ... }

パラメータ

sort_column (string)
Sorts the list of Pages in a number of different ways. The default setting is sort alphabetically by Page title.
  • 'post_title' - Sort Pages alphabetically (by title) - default
  • 'menu_order' - Sort Pages by Page Order. N.B. 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 Write>Pages administrative 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.

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)
Change the sort order of the list of Pages (either ascending or descending). The default is ascending. Valid values:
  • 'asc' - Sort from lowest to highest (Default).
  • 'desc' - Sort from highest to lowest.
exclude (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.
include (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)
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 - Pages and sub-pages displayed in hierarchical (indented) form (Default).
  • -1 - Pages in sub-pages displayed in flat (no indent) form.
  • 1 - Show only top level Pages
  • 2 - Value of 2 (or greater) specifies the depth (or level) to descend in displaying Pages.
child_of (integer)
Displays the sub-pages of a single Page only; uses the ID for a Page as the value. Defaults to 0 (displays all Pages).
show_date (string)
Display creation or last modified date next to each Page. The default value is the null value (do not display dates). Valid values:
  • '' - 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)
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 (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 <ul>, </ul> tags. See the example for Headings.
echo (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)
hierarchical 
(boolean) Display sub-Pages in an indented manner below their parent or list the Pages inline. The default is true (display sub-Pages indented below the parent list item). Valid values:
  • 1 (true) - default
  • 0 (false)
meta_key 
(string) Only include the Pages that have this Custom Field Key (use in conjunction with the meta_value field).
meta_value 
(string) Only include the Pages that have this Custom Field Value (use in conjuntion with the meta_key field).


記事

コードドキュメンテーション

  • クラス: WP_Query - WP_Query クエリの詳細概要
  • オブジェクト: $wpdb - $wpdb オブジェクトの使い方概要
  • 関数: get_query_var()
  • 関数: query_posts() - 追加カスタムクエリの作成
  • 関数: get_post() - 項目の ID を使ってその投稿のレコードをデータベースから取得する
  • 関数: get_posts() - 項目の配列を返す特別な関数。
  • 関数: get_pages() - ページの配列を返す特別な関数。
  • 関数: have posts() - クエリが記事を返すかどうか判断する条件分岐。
  • 関数: the_post() - クエリの後に自動的にループを設定するのに使われる。
  • 関数: rewind_posts() - 現在のループをクリアする。
  • 関数: setup_postdata() - ループ内で単一クエリ結果のデータを設定する。
  • 関数: wp_reset_postdata() - 以前のクエリを復元する(通常、ループ内のもう一つのループで使われる)。
  • 関数: wp_reset_query()
  • 関数: is_main_query() - 変更するのがメインクエリであるよう保証する。
  • アクションフック: pre_get_posts - 実行される前に WordPress クエリを変更する。
  • アクションフック: the_post - 投稿オブジェクトをクエリの後に変更する。
  • フィルターフック: found_posts - found_posts WP_Query オブジェクトの値を変更する


関連

固定ページ: get_all_page_ids(), get_ancestors(), get_page_link(), get_page_by_path(), get_page_by_title(), get_page_children(), get_page_hierarchy(), get_page_uri() /en, get_pages(), is_page(), page_uri_index() /en, wp_list_pages(), wp_page_menu()


リスト・ドロップダウン関数: 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()


テンプレートタグへのクエリ文字列型パラメータの渡し方関数リファレンステンプレートタグ目次もご覧ください。


最新英語版: WordPress Codex » Template Tags/wp_list_pages最新版との差分