Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 指定したIDの子孫を階層でリスト表示 | |
$parent = ここに親のID; | |
$args=array( | |
'child_of' => $parent | |
); | |
$pages = get_pages($args); | |
if ($pages) { | |
$pageids = array(); | |
foreach ($pages as $page) { | |
$pageids[]= $page->ID; | |
} | |
$args=array( | |
'title_li' => '', | |
'include' => $parent . ',' . implode(",", $pageids) | |
); | |
wp_list_pages($args); | |
} | |
?> |
Screen shot
上のSSは「レベル1」というタイトルの固定ページが最上位の親なので、その固定ページのIDを指定しています。表示ページは孫ページ。
ページテンプレート等でメインコンテンツとは別の特定のコンテンツを固定ページで作った際のリスト表示等に使いました。
Note
Description | 親のIDを指定して、その親に属する子孫と親自身の全てのリンクリストを階層で表示する |
---|---|
WordPress Ver. | 4.4.4 |
Via | テンプレートタグ/wp list pages – WordPress Codex 日本語版 |