我發現在這些情況下最適合我的是忘記使用wp_list頁面。相反,進行查詢,然後遍歷結果以獲取頁面子元素。
例子:
<ul>
<?php
$args = array(
'include' => array(138, 110, 135, 101, 167),
'orderby' => 'post_date',
'post_type'=> 'page',
);
/* Get posts according to arguments defined above */
$pages = get_posts($args);
echo "<ul>";
/* Loop through the array returned by get_posts() */
foreach ($pages as $page) {
/* Grab the page id */
$pageId = $page->ID;
/* Get page title */
$title = $page->post_title;
echo "<li>$title</li>";
/* Use page id to list child pages */
wp_list_pages("title_li=&child_of=$pageId");
/* Hint: get_posts() returns a lot more that just title and page id. Uncomment following 3 lines to see what else is returned: */
//echo "<pre>";
//print_r($page);
//echo "</pre>";
}
echo "</ul>";
?>
</ul>
而且你的輸出應該是這個樣子:
<ul>
<li>Parent Page1<li>
<ul>
<li>Child page1</li>
<li>Child page2</li>
<li>Child page etc</li>
</ul>
<li>Parent Page2</li>
<ul>
<li>Child page1</li>
<li>Child page2</li>
<li>Child page etc</li>
</ul>
...and so forth
</ul>