Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress-在所述子页面上显示父页面的子页面_Php_Wordpress - Fatal编程技术网

Php Wordpress-在所述子页面上显示父页面的子页面

Php Wordpress-在所述子页面上显示父页面的子页面,php,wordpress,Php,Wordpress,我有以下层级顺序: Parent Page Child Page 1 Child Page 2 Child Page 3 我使用以下PHP代码片段在侧导航中显示父页面上的所有子页面: wp_list_pages('title_li=&child_of='.$post->ID.'&echo=1'); 现在回答我的问题: 如何修改代码段,使其同时在子页面上显示侧导航?不知何故:“转到父页面,收集所有子页面,并在子页面上显示您所在的位置” 谢谢你

我有以下层级顺序:

Parent Page
     Child Page 1
     Child Page 2
     Child Page 3
我使用以下PHP代码片段在侧导航中显示父页面上的所有子页面:

wp_list_pages('title_li=&child_of='.$post->ID.'&echo=1');
现在回答我的问题:

如何修改代码段,使其同时在子页面上显示侧导航?不知何故:“转到父页面,收集所有子页面,并在子页面上显示您所在的位置”

谢谢你的阅读

wp_list_pages('title_li=&child_of='.$post->post_parent.'&echo=1');
此代码段将返回当前页面及其同级。但是,这将只返回当前页面父级的子级。如果需要获取深度嵌套层次结构的页面,则应使用:

global $post;
    /* Get an array of Ancestors and Parents if they exist */
$parents = get_post_ancestors( $post->ID );
    /* Get the top Level page->ID count base 1, array base 0 so -1 */ 
$id = ($parents) ? $parents[count($parents)-1]: $post->ID;
wp_list_pages('title_li=&child_of='.$id.'&echo=1');