I have created a child page. However, when I access "http://example.com/Page/ChildPage" does not appear?

Page (filename = page.php -> content-page.php) [WORK]

Child Page (filename = page.php -> content-child-page.php) [NOT WORK]


$slug = get_post_field( 'post_name', get_post() );
echo $slug;

while ( have_posts() ) : the_post();

    get_template_part( 'template-parts/page/content' , $slug );

endwhile; // End of the loop.

Admin screen for all page

View donation page

Child page from donation. When clicking on the child page is redirected to the homepage



  • The $slug is child-page? – Shibi Dec 26 '17 at 10:41
  • The $slug is get current page. There is something wrong? – Iman Himawan Dec 26 '17 at 10:46
  • What? when you do echo $slug; what do you see? – Shibi Dec 26 '17 at 10:48
  • slug from Page. – Iman Himawan Dec 26 '17 at 10:51
  • Is there a different way to get slug for child page? I think that's how it works. – Iman Himawan Dec 26 '17 at 10:55

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.
  • The problem is the child page does not read the file from page.php – Iman Himawan Dec 26 '17 at 11:21
  • When you enter the child page what happend? do you see the echo $slug; output? You maybe select different page template in the child page? – Shibi Dec 26 '17 at 11:28
  • Nothing appears (including echo $ slug). – Iman Himawan Dec 26 '17 at 11:38
  • Need to see some screenshots of your edit and view for the child page and the child page view source code – Shibi Dec 26 '17 at 11:49
  • I have added some source code and screenshoot. I hope this help. – Iman Himawan Dec 26 '17 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.