0

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]

page.php

$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

page.php

content-payment.php

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

1 Answer 1

0

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.
7
  • The problem is the child page does not read the file from page.php Commented Dec 26, 2017 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
    Commented Dec 26, 2017 at 11:28
  • Nothing appears (including echo $ slug). Commented Dec 26, 2017 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
    Commented Dec 26, 2017 at 11:49
  • I have added some source code and screenshoot. I hope this help. Commented Dec 26, 2017 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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