Child pages and sub-pages do not appear. Why?

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.

Topic child-pages Wordpress

Category Web


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.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.