adding is in tree function to the functions file
authorAnthony Talarico <talarico@gaslightmedia.com>
Wed, 9 May 2018 12:37:49 +0000 (08:37 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Wed, 9 May 2018 12:37:49 +0000 (08:37 -0400)
functions.php

index 7fb5f80..5937126 100644 (file)
@@ -177,7 +177,27 @@ function is_post_type($type){
     if($type == get_post_type($wp_query->post->ID)) return true;
     return false;
 }
-
+/*
+ * This function returns true when the current page is the page given by ID
+ *  or a descendent thereof.
+ */
+if (!function_exists('is_in_tree')) {
+    function is_in_tree( $pid ) {
+        global $post;
+        if ( is_page( $pid ) ) {
+            return true;
+        }
+        if ($post) {
+            $anc = get_post_ancestors( $post->ID );
+            foreach ( $anc as $ancestor ) {
+                if( is_page() && $ancestor == $pid ) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+}
 add_action('thematic_searchloop', 'mytheme_search_loop');
 // End of the Contextual/Highlight Search functions
 ?>