If you have multiple sub pages of child pages, then you may need to find out the depth of the page. It’ll help you get the level of your page and also tells if its the parent page.
Instructions: Add the following code to the functions.php file of your WordPress theme.
<?php /** * Get current page depth * * @return integer */ function get_current_page_depth(){ global $wp_query; $object = $wp_query->get_queried_object(); $parent_id = $object->post_parent; $depth = 0; while($parent_id > 0){ $page = get_page($parent_id); $parent_id = $page->post_parent; $depth++; } return $depth; } ?>
You may also enjoy using category parent template.
Comments Leave a Reply