Try using get_post_ancestors. Here is how you can apply this in your case:
<?php
global $wp_query;
$post = $wp_query->post;
$ancestors = get_post_ancestors($post);
if( empty($post->post_parent) ) {
$parent = $post->ID;
} else {
$parent = end($ancestors);
}
if(wp_list_pages("title_li=&child_of=$parent&echo=0" )) {
wp_list_pages("title_li=&child_of=$parent&depth=1" );
}
?>
You’ll probably need to remove the depth parameters to show you’re 3rd level pages.
Let me know if this helps!
Related Posts:
- Conditional tag to check if ‘page.php’ is being used?
- Listing pages which uses specific template [duplicate]
- WordPress page edit does not save selected template
- Set page template automatically based on parent
- Is there a default template file for child pages / subpages?
- How to display code if it is not certain pages?
- Multiple areas of dynamic content in a page
- How do I set and list page_template with wpcli?
- How do I modify this page template to show subpage excerpts (not post excerpts)?
- Limit number of pages that use a specific template?
- How to inject custom url path for page ?
- How does wordpress calculate the page depth?
- List all pages and children in separate ul
- Dynamically Load Styles and Scripts from Theme Functions.php
- Add custom admin menu item for pages using a certain template
- What’s the most minimal way in which a page can be hooked into WP?
- How do I create multiple page while active a theme
- How to make certain page templates visible to admin only
- Check whether the child page has siblings
- How to dynamically save a selected option from page “Templates” selectbox?
- Modify Page Title before output via wp_page_list
- Extra title output with this function wp_list_pages
- How to add meta boxes to Pages
- Custom page template not working
- Dynamically change page that loads
- How do I pass data from page content to the underlying PHP template
- List pages by custom field?
- Password Protected Page Title
- List child pages by slug not ID?
- Determine page content based on page parent
- Displaying page content in category archive (archive.php)
- How to enumerate a list of posts?
- Missing ‘Page Attributes’ in page edit
- Combining ‘depth’ with ‘include’ in wp_list_pages()
- Could be a namespace conflict (?) with login form and register form on the same page
- Get the ID of the direct parent page
- Custom page template for multiple pages
- My custom template page not loading content inside it?
- Custom page with queries returns 404
- How to capture GET argument on static page
- JQuery Plugins in WordPress
- the_content of template page
- Post Fetching Ignoring Sort_Column?
- Remove comment section from new page
- WordPress theme: Add page content to the bottom of the Contact form
- Dynamic href link to Contact Page
- Exclude pages by menu order
- WordPress 3.2 – removed ability to select a page template in the page attributes when adding a new page?
- Change page name in admin list
- Use same page-mypage.php template for several pages
- Check if the child page has sibling pages, and bookmark current page
- How do you implement a page template automatically being applied to a page?
- How do I edit text displayed on my browser tab?
- How to create different template designs for different pages in WordPress [closed]
- Different css file not working for the page template I created
- Keep page hierarchy in wp_list_pages, even if on a child or grandchild
- require_once not working
- Displaying posts on homepage – Template Page
- Page templates in subdirectories and auto generator
- WordPress Page doesn’t load the template selected
- Use page template for custom $_GET content
- How to bypass 404 for certain pages/posts?
- Outputting content from page
- Custom folder for wordpress page templates
- Authors posts on a author created page
- Check if page has subpages
- wp_nav_menu: output featured image of each page listing
- Static Website No Titles But Still Nav
- page template – undefined structure in source code
- Translate dashboard metabox
- My pages are using my Index.php and not my page.php
- WordPress custom pages in a folder
- Create page template
- Include parent page in list of child pages
- wp_list_pages get the hole hierarchy for current page
- WordPress blog posts template bug [closed]
- Add homepage to the list of pages in the Footer Widget
- How to detect if some page template has been selected
- WordPress form submit to custom page template does not work
- Remove and change pages label
- Using external DB within wordpress
- What’s the best way to manage sections on a page?
- WordPress Page All Content In Template Good Or Bad Convention?
- How do you assign custom template for Posts page (under Front page displays setting)
- Get All Pages as strings in array
- Content template when adding a new page
- How to display time when page is created and edited
- Call a function on every wordpress pages only
- How To List Sibling Pages And Include The Featured Image?
- Specify parent page template
- WP Template Hierarchy – Need help choosing the correct templates
- Custom Filter using meta_value in wordpress admin list not working
- how bbPress and buddypress add their own page templates to the page template drop down on the page editing screen
- Showing certain page without redirection
- How to make in post Parent page children page list nummbered
- Create a new page for each form selection
- link a custom page into menu
- exclude page element from specific pages
- Custom wp_list_pages() function
- May I know where to edit the tax rate?