I'm serving a different header in Wordpress depending what section you are within the site, 'residential' , 'business' or other by using the following code. Although i need to extend it to work with grandchildren as well, so another level down.
<?php
/*
Template Name: Package
*/
if (is_page('business') || $post->post_parent=="17")
{
get_header('business');
}
else if (is_page('residential') || $post->post_parent=="19")
{
get_header('residential');
}
else
{
get_header();
}
?>
I'm serving a different header in Wordpress depending what section you are within the site, 'residential' , 'business' or other by using the following code. Although i need to extend it to work with grandchildren as well, so another level down.
<?php
/*
Template Name: Package
*/
if (is_page('business') || $post->post_parent=="17")
{
get_header('business');
}
else if (is_page('residential') || $post->post_parent=="19")
{
get_header('residential');
}
else
{
get_header();
}
?>
Share
Improve this question
edited Jun 28, 2012 at 15:17
Stephen Harris
32.6k6 gold badges84 silver badges118 bronze badges
asked Jun 28, 2012 at 14:54
Roy BarberRoy Barber
1211 silver badge4 bronze badges
2 Answers
Reset to default 2get_ancestors()
will return the full parent page ID hierarchy for a given page ID which you could check against.
You can count post ancestor like this
$count = count(get_post_ancestors($post->ID));
The results means:
2= grandchild
1= child
0=parent