Change the WordPress Template for page.php if it has children
<?php get_header(); ?> | |
<?php | |
if (have_posts()) : while (have_posts()) : the_post(); | |
$pid = get_the_ID(); | |
$args = array( | |
'post_parent' => $pid, | |
'post_type' => 'page', // Change as per post type | |
'numberposts' => -1, | |
'post_status' => 'publish' | |
); | |
$childp = get_children( $args ); | |
$numposts = count ( $childp ); | |
if( $numposts == 0 ) { | |
get_template_part( 'page-single' ); // Template part if no children | |
} | |
else { | |
get_template_part( 'page-parent' ); // Template part if has children | |
} | |
endwhile; endif; | |
?> | |
<?php get_footer(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment