I am trying to display a child page template of a certain specific parent page.
<?php
if(has_children()){
// This is a parent page
get_template_part('content', 'parent');
}elseif(is_page() && $post->post_parent ){
// This is a child page of certain parent page
get_template_part('content', 'child');
//*THIS PART BELOW HAS REFUSED TO WORK FOR THE CHILD PAGE OF PARENT PAGE ID 689
}elseif(is_child_of(689)){
// This is a child page of Parent page having id 689
get_template_part('content', 'park');
}else{
//This is default for anyother page
get_template_part('content', 'default');
}
?>
The code above, when trying to get the child page of the parent page(689), still renders or rather displays the get_template_part('content', 'child');
and not get_template_part('content', 'park');
which i want.
I am trying to display a child page template of a certain specific parent page.
<?php
if(has_children()){
// This is a parent page
get_template_part('content', 'parent');
}elseif(is_page() && $post->post_parent ){
// This is a child page of certain parent page
get_template_part('content', 'child');
//*THIS PART BELOW HAS REFUSED TO WORK FOR THE CHILD PAGE OF PARENT PAGE ID 689
}elseif(is_child_of(689)){
// This is a child page of Parent page having id 689
get_template_part('content', 'park');
}else{
//This is default for anyother page
get_template_part('content', 'default');
}
?>
The code above, when trying to get the child page of the parent page(689), still renders or rather displays the get_template_part('content', 'child');
and not get_template_part('content', 'park');
which i want.
1 Answer
Reset to default 1Try this... Your code is hitting elseif(is_page() && $post->post_parent )
and stopping there.
<?php
if(has_children()){
// This is a parent page
get_template_part('content', 'parent');
}elseif(is_page() && $post->post_parent ){
// This is a child page of certain parent page
if(is_child_of(689)){
// This is a child page of Parent page having id 689
get_template_part('content', 'park');
}else{
get_template_part('content', 'child');
}
}else{
//This is default for anyother page
get_template_part('content', 'default');
}
?>