If you are working with pages in WordPress that have sub-pages, there is a chance that at some point you are going to need to add conditions that apply to these sub-pages.
This is pretty easy and can be done by putting the following code in the relevant template file:
<?php if ($post->post_parent == "123") { // If the page parent ID is 123, do stuff here... } ?>
Now, if you have sub-pages that have more sub-pages and you want a condition to apply to all pages under the “grandparent” page, simply use the following code:
<?php $ancestors = get_post_ancestors($post); if (in_array(123, $ancestors)) { // If the page grandparent ID is 123, do stuff here... } ?>