WordPress - 仅列出 1 层儿童 [英] WordPress - listing only 1 tier of children

查看:26
本文介绍了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

.

这篇关于WordPress - 仅列出 1 层儿童的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆