You need to check if the page have parent to display the child page template or if he doesnt have to display the parent page template. If $post->post_parent is equal to 0 thats mean that he doesnt have a parent.
while ( have_posts() ) : the_post();
$template = ($post->post_parent == 0) ? 'page' : 'child-page';
get_template_part( 'template-parts/page/content' , $template );
endwhile; // End of the loop.
Related Posts:
- how to properly list child pages in sidebar?
- Get custom field value from Grandparent Page for Parent and Child Pages
- Given the page id, check if it has children
- How to get a list of all recently published child pages?
- WordPress get the child pages of current page
- Show siblings (if any) and parents
- List child pages of current page but limit to specific year
- Child page excerpt
- Create WordPress child page from page actions
- How to show child page without providing ID so it’s dynamic
- is_child() function
- Drop-Down Menu of Current Child Pages
- Get WordPress Child Page IDs
- Displaying the first child page of the parent page
- Adding title and description to subpage’s featured image
- Show list of Child Post in Parent Post
- List subpages in order
- parent page grabbing wrong url for child pages – get_page_uri($pageChild)
- i want to get the parent id, only on parent -> child -> child page
- Get first level children of a page ID
- Only one parent page showing
- Create a list of pages excluding children of selected page
- WordPress Betheme: Unkown subheader image of a child page
- How to disable alphabetical sorting page
- Structure for calling child pages
- Add link to parent page in list of child pages
- Display child pages full template including the content
- List child pages, exclude the current page
- Listing Child Pages in Random order
- How to display child pages with in a limited child content?
- Display Tags of Child Pages
- Get post_meta of children and compare to current page ID
- Display the latest content from subpages of another page
- Limit the number of child page displaying
- Show the grandmother/father of the childpage
- How to Hard Set the Parent Page in Template
- Website parent child relationship
- Automatically create child pages when saving a (parent) page
- Allow only new sub-pages to be created
- 404 on child page when parent page slug is identical to custom post type
- Prev/Next child navigation for current page?
- How can I programmatically create “child” pages on theme activation?
- List child pages of a specific page
- Some pages are missing from the Parent Page select in the Editor
- Create child page within custom post type
- Remove parent slug for child pages
- Using pagination with get_posts on page type
- Easy way to process search results before displaying
- Add class to the items in wp_list_pages
- Load parent pages when there are no child pages
- Displaying child page content of a certain parent
- Get only the grandchildren, not the direct children of page/current page?
- Remove custom post type slug not working for child pages
- Page as a child of a Custom Post Type
- select a private page as parent for another private page
- Deleted pages showing up when querying for child pages
- get_posts() excluding all children of a specific post/page
- How to add numeric slug for child page in WordPress 5.9?
- Set order of returned items in the WP_Query() class/function
- Pagination of a WP_Query Loop in a child-page page template
- Schedule Page to Menu [duplicate]
- get permalink of page children in loop
- List child pages by slug not ID?
- Display the contents of a custom field of a page on their child
- How to hide all child pages with post_query?
- Child post with numeric only slug keeps redirecting to parent
- Next and Previous Posts of Same Parent
- How to display all subpages and short by year
- Sort order of next/prev sibling page
- Display Child Pages of Custom Post Type Parent Page
- get_pages() & “child_of”
- What code should I use to display children of a custom post?
- How to populate a parent page with its child subpages and associated templates
- Listing subpages title and content and styling the first iteration differently
- Removing Parent Page URL While Keeping the Navigation Intact
- Organizing Your Pages
- Custom page template for multiple pages
- query if page has not child
- Return value of get_permalink(0) and get_the_title(0)
- How to have a custom URI path for specific page template
- complex get_posts() query to select child pages
- Page access only from a specific page in wordpress website
- $pages = get_pages(‘child_of=’.$post->ID); Why arguments are concatenated?
- Do we need to change our child function.php to require/include child dir files when we add an over-riding file.php into the child theme
- How to hightlight all ancestor menu items of a child page NOT displayed in menu
- Page that links to category content
- Exclude child pages args array
- Show child by slug, while knowing parent ID
- Child Theme not overwriting Parent theme php file
- Standard Page Child of CPT Not Found (404)
- Creating navigation out of specific IDs and their children?
- If page or sub page not working as expected
- How to use wp_dropdown_pages or wp_list_pages to accomplish a menu like this?
- Load one page with parent and child pages
- List of child pages fetch next results at link click
- Pages redirecting to homepage
- Showing main menu and child menu in diffent places in a same page
- How to check if the current page’s parent is one of 2 different ID’s
- How to make in post Parent page children page list nummbered
- List of pages – AJAX load more