WordPress - 仅列出 1 层儿童

问题描述:

使用下面的代码,如何仅显示与当前页面关联的直接子级集,而不显示子级的子级或该页面层上的其他父级.我假设深度参数是解决方案的一部分,但是我不确定如何最好地实现它.此外,深度是指绝对还是相对的层次结构.我希望它相对于所选页面仅显示 1 个深度级别.

Using the code below, how can I display only the immediate set of children associated with the current page and not the children's children or the other parents on the tier of that page. I assume that the depth parameter is a part of the solution however, I'm unsure as to how to best implement it. Also, does the depth refer to the hierarchy in an absolute or relative fashion. I'd like for it to show only 1 level of depth relative to the page that is selected.

非常感谢您的帮助,如果我能提供任何说明,请告诉我.

Thank you much for the help and if I can offer any clarification, please let me know.

 <?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 } ?>

depth 是这样使用的:

depth is used in this way:

wp_list_pages("depth=1&title_li=&child_of=".$post->ID."&echo=0");

如果你使用这个会怎样?

What happens if you use this one?

来自文档:

深度:(整数)此参数控制页面层次结构中的多少级别将包含在 wp_list_pages 生成的列表中.默认值为 0(显示所有页面,包括所有子页面).

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(默认)以任意深度显示页面并在嵌套列表中分层排列

0 (default) Displays pages at any depth and arranges them hierarchically in nested lists

-1 以任意深度显示页面并将它们排列在一个单一的平面列表中

-1 Displays pages at any depth and arranges them in a single, flat list

1 仅显示顶级页面

2, 3 ... 显示给定深度的页面

2, 3 … Displays Pages to the given depth

.