-
-
Save jimmynotjim/4723465 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* =BEGIN: Check If Page Is Parent/Child/Ancestor | |
| Source: http://www.stemlegal.com/greenhouse/2012/checking-ancestor-and-parent-pages-in-wordpress/ | |
| ---------------------------------------------------------------------------------------------------- */ | |
| function is_tree( $page_id_or_slug ) { | |
| global $post; | |
| if ( !is_numeric( $page_id_or_slug ) ) { // Used this code to change a slug to an ID, but had to change is_int to is_numeric for it to work: http://bavotasan.com/2011/is_child-conditional-function-for-wordpress/ | |
| $page = get_page_by_path( $page_id_or_slug ); | |
| $page_id_or_slug = $page->ID; | |
| } | |
| if ( is_page( $page_id_or_slug ) ) | |
| return true; | |
| $anc = get_post_ancestors( $post->ID ); | |
| foreach ( $anc as $ancestor ) { | |
| if ( is_page() && $ancestor == $page_id_or_slug ) { | |
| return true; | |
| } | |
| } | |
| return false; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment