我有以下层次顺序:
Parent Page
Child Page 1
Child Page 2
Child Page 3
我使用以下PHP代码段在侧面导航中显示父页面上的所有子页面:
wp_list_pages('title_li=&child_of='.$post->ID.'&echo=1');
现在问我的问题:
如何修改它还显示子页面上的侧面导航的代码段?不知何故:'转到您的父页面,收集所有子页面并在子页面上显示它。“
感谢阅读!
答案 0 :(得分:2)
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');