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
- wp query to get child pages of current page
- A check for if is parent page, if has children, if has grandchildren
- Custom user role that can only edit specific (non-custom-type) page and all child pages [duplicate]
- Keeping parent menu items active in child pages
- Breadcrumbs showing Parent and Child Pages
- How to display list of child pages of parent page in wordpress?
- Display subpages under parent page as a list within a loop
- Remove parent slug for child pages
- get_pages – Display child then grandchild pages
- Do not show child pages of child pages
- Can’t change parent page
- List the 5 most recent child pages
- Does WordPress automatically redirect url without parent slug?
- inserting custom li class to wp_list_pages
- Multiple Conditions for Child Page Title
- Child page in custom post throws 404 page not found
- Show child pages when on a child page
- query attachment images … if no attachments -> get attachments of parent page?
- How to target children of child pages
- Custom page slug without creating a WP page
- Custom Field returning Numerical Value for Image rather than URL
- Search pages that are a child of the current page
- Injecting a custom sql query into a page/theme
- List all-childpages on parent-page AND list child-pages on childpage itself but not the current one?
- Menu with parents, children and or siblings pages display
- Linking to Child Theme PHP Files
- Trouble with parent and child conditional tag to show content
- Use same page template for parent and child pages in a theme
- Advanced Custom Fields dynamic update_field
- Child page menu in sidebar
- Trying to return list of child pages for a template
- Parent/child pages and link structure the right way
- List Posts For Terms Of A Custom Taxonomy For Any Post Type
- get_the_title() gets printed out twice
- Active Menu Highlighter with Subpages?
- Display child pages in sidebar of parent page in wordpress
- Get Top parent url
- Display child pages in a parent page? [closed]
- How to Create a Random List of Child Pages
- List all posts with the parent or grandparent of a page with a specified ID
- Query to list all galleries under a parent post?
- Keep page hierarchy in wp_list_pages, even if on a child or grandchild
- Sort and display pages with specific custom field (not tag)
- How to use wp_list_pages on a grandparent page
- If/Else child list for Custom Post Type single template within loop?
- Search anything from a Child and Sub-Pages of their Parent page
- How do I find out which (page) template file my custom child post is looking for?
- How to get an array of pages ID by some page’s slug and all its children pages in get_posts() function?
- How to use POST method using custom wordpress button?
- Getting a value from a custom field from a page that shares a parent with the current page
- One set of Child Pages redirecting to Home page?
- Displaying Child Page’s Information
- PHP: Why does my code work in index.php but not a widget?
- How to show children pages as array
- Page permalink ending in “-2”
- Childpage title + content on Parent Page
- Sidebar current menu item for parent
- Preventing PHP Execution in Parent Theme
- Display title of child pages in shortcode
- Elegant way to signify inheritance and relationship between posts
- How to finish this loop?
- 404 error on second page load for child-pages
- Query sub subpages based on specific date?
- Subpages menu on sidebar plus widgets