Your code won’t work if you have more than one parent page or multiple levels of child pages. Use get_ancestors
to get the top parent page, and use the child_of
argument of wp_list_pages
rather than exclude
to only output pages from that branch.
Related Posts:
- How can I hide children of draft pages using wp_list_pages()?
- How to List All Pages (With their template names) Within a Website
- How can I list all pages with their templates?
- Add Parent to List of Subpages
- get all page IDs from wp_list_pages
- Add class to the items in wp_list_pages
- Display grandchildren on child and grandchild pages using wp_list_pages
- Load parent pages when there are no child pages
- create shortcode to show children if any otherwise siblings
- dynamically limit depth of wp_list_pages
- Conditional styling of wp_list_pages bullet points [closed]
- Setting multiple values to as sort_column
- wp_list_pages – Using a Walker to customize output order
- Custom category listings
- How can I include private pages in a page list?
- Do Not Display Parent Page if No Subpages
- Arrange Combined List of Pages and Categories
- List pages within a certain parent and show published month
- Change Parent Name with wp_list_pages?
- List all Posts under heading in wp_list_pages menu
- $item->url not retrieving url in custom walker?
- WordPress Side Navigation with Parent Heading and Child Sub Pages
- List subpage of subpage
- wp_list_page with something like showpost
- How can I list all page titles and IDs?
- Hide Parent if No Children
- Add Parent to Subpage List
- active parent page when clicked on childpage
- alternating classes on wp_list_pages
- remove auto generated pages from the menu?
- Inset image thumbnail from page into list
- How to prevent custom walker from creating sub navigation for pages that are not relatives of the current page?
- Sub Navigation in Sidebar
- wp_list_pages bug in “number” parameter
- Targeting specific instane of wp_list_pages
- Renaming wp_list_pages class
- wp_list_pages issue/bug?
- WordPress get_pages sub nav show current page
- Change class name in WordPress wp_list_page nav
- Non page link in wp_list_pages
- only display Pages which have children
- add a.parent in wp_list_pages
- wp_list_pages by taxonomy?
- wp_list_pages Format only on Recently Modified Pages
- Adding custom class names to anchor in wp_list_pages
- Walker Class : extract function and wp_list_pages
- Exclude pages by custom field (with yes/no) storing wrong data?
- How to hook wp_list_pages?
- How does wordpress calculate the page depth?
- How to show only parents subpages of current page item in vertical menu?
- Change ul class=”children” for wp_list_pages?
- how to properly list child pages in sidebar?
- Add filter to wp_dropdown_pages() or wp_dropdown_categories() – no select container?
- Custom Post Type Name Causing Problem
- No link on empty page in wp_list_pages
- wp_list_pages sort order is different for different languages [closed]
- Extra title output with this function wp_list_pages
- wp_list_pages: only show subpages on the parent page?
- How to have custom menu Item CSS Classes for wp_page_menu() or wp_list_pages()
- Highlight another nav item
- How would I add the comment count to this sub-pages of current page snippet
- Show siblings (if any) and parents
- Populate meta select box with child pages
- Menu with parents, children and or siblings pages display
- wordpress wp_list_pages help
- Append a code when at the current page in wp_list_pages()
- Combine get_page_by_title to exclude pages from wp_list_pages
- Combining ‘depth’ with ‘include’ in wp_list_pages()
- HowTo preserve page hierarchy with wp_list_pages()?
- Get Parent List Class for Child Pages Using Walker
- Get the ID of the direct parent page
- Exlude pages from wp_list_pages
- Get parent of current page
- wp_list_pages() exclude category
- Exclude pages by menu order
- Single-page wordpress theme navigation
- Change page name in admin list
- Displaying pages with a specific custom meta
- How can I list the current pages siblings and any ancestor page siblings?
- Dynamic menu wp_list_pages displaying only current branch including: current page, his siblings and its childs
- WP List Pages – Add Title Attributes to Anchors
- wp_list_pages Hierarchical Help
- List all pages including archive
- Getting subpage of subpage – Custom posts
- Add classes + taxonomy terms to wp_list_pages() output
- Disable the link on certain pages
- List all files from subpages
- Translate dashboard metabox
- wp_list_pages two columns
- Retrieve array items without page ID
- Create a list of pages excluding children of selected page
- Highlight Single Page Ancestor
- List pages including both parent and child pages
- PHP: Why does my code work in index.php but not a widget?
- Why is wp_list_pages altering $post->ID of the page?
- Get current post’s child page?
- Display a custom post type list by taxonomy term
- WordPress function breaks widget’s markup?
- Second tier sidebar navigation
- current_page_item and custom post type?