admin管理员组文章数量:1333054
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
本文标签: templatesIf Child or Grandchild of Page
版权声明:本文标题:templates - If Child or Grandchild of Page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742272444a2444561.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论