How do you detect if a page is a grandchild and execute some code only on that page and not on the grandpa or the parent?
Thanks!
How do you detect if a page is a grandchild and execute some code only on that page and not on the grandpa or the parent?
Thanks!
Thanks but that does not answer my question. I need to know if a page is a grandchild not a child. The codex snippets only talk consider one level of separation, I need two.
Why doesn't the core include a nice "is_grandchild" function?
PS: I tried this http://www.web-templates.nu/2008/09/07/get-depth-like-is_child-is_grandchild/ and similar to no avail....
Hi, Thanks but I had already tried that, and it did not work. However I am not sure I understood the following comment from the original poster and therefore modified the code appropriately.
This is the comment quote:
"Why thank you! I had to Booleanate the function (renamed to is_grandchild) and changed line 7 to "return true". – "
What I did, I renamed the function, then applied the change on line 7 but it did not work the same. I am not sure I understand what he means for Booleanate.
a boolean function returns TRUE or FALSE. so you can test it with (on a Page):
if (get_grandpapa($posts[0]->ID)) {
// do stuff
}AH! Thanks! I added this
function get_grandpapa($page_id){
$current_page = get_page( $page_id );
if ($current_page->post_parent > 0){
$parent_page = get_page($current_page->post_parent);
if ($parent_page->post_parent > 0){
return $parent_page->post_parent;
}else{return false;}
}return false;};
in the functions file, the called the boolean in the template file. Thanks it works!
You must log in to post.