Wordpress 如何显示子页面的所有子项?

Wordpress how to display the all children of a child page?

我正在使用下面列出当前父页面的所有子页面。我现在需要列出子页面的子页面...这可能令人困惑..

获取当前页面 ID > 显示该页面 ID 的所有直接子页面 > 我现在还需要显示当前页面的子页面...

很喜欢:

 - Child page 
   - Child of Child page
   - Child of Child page
 - Child page 
<div class="nav-col">
    <?php 
    global $post;
    $direct_parent = $post->post_parent;
    ?>
    <div class="side-nav">
    <?php 
    wp_list_pages(array(
        'child_of'    => $direct_parent,
        'title_li' => ""
    ));
    ?>
    </div>
</div>

wp_list_pages 采用名为“深度”的参数。你可以用它来解决你的问题。

您可以分配给“深度”的值:

  • -1(任意深度)
  • 0(所有页面)
  • 1(仅限顶级页面)
  • n(页面到给定的 n 深度)
  • 默认 0
<div class="nav-col">
  <?php 
    global $post;
    $direct_parent = $post->post_parent;
  ?>
  <div class="side-nav">
  <?php 
    $args = array(
      'child_of'    => $direct_parent,
      'title_li'    => "",
      'depth'       => -1
    );
    wp_list_pages($args);
  ?>
  </div>
</div>

文档:
https://developer.wordpress.org/reference/functions/wp_list_pages/