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');