Title: is_tree()
Last modified: August 19, 2016

---

# is_tree()

 *  [jimmyt1988](https://wordpress.org/support/users/jimmyt1988/)
 * (@jimmyt1988)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/is_tree/)
 * I added this function to my functions.php:
 *     ```
       <?php
           function is_tree($pid) {      // $pid = The ID of the page we're looking for pages underneath
           	global $post;         // load details about this page
           	$anc = get_post_ancestors( $post->ID );
           	foreach($anc as $ancestor) {
           		if(is_page() && $ancestor == $pid) {
                       return true;
           		}
           	}
           	if(is_page()&&(is_page($pid)))
                   return true;   // we're at the page or at a sub page
           	else
                   return false;  // we're elsewhere
           };
       ?>
       ```
   
 * and I am executing it outside of the loop:
 *     ```
       <?php
           if (is_tree('home')){
               echo '<img src = "' . $siteUrl . '/images/content_title_productivityOptimisation.jpg" alt = "Welcome Title" />';
           }
           elseif (is_tree('partners')){
               echo '<img src = "' . $siteUrl . '/images/content_title_partner.jpg" alt = "Welcome Title" />';
           }
           elseif (is_tree('blog')){
               echo '<img src = "' . $siteUrl . '/images/content_title_blog.jpg" alt = "Welcome Title" />';
           }
           elseif (is_tree('contact')){
               echo '<img src = "' . $siteUrl . '/images/content_title_contact.jpg" alt = "Welcome Title" />';
           }
           elseif (is_tree('productivity-tools')){
               echo '<img src = "' . $siteUrl . '/images/content_title_productivityTools.jpg" alt = "Welcome Title" />';
           }
           elseif (is_tree('training-workshops')){
               echo '<img src = "' . $siteUrl . '/images/content_title_trainingWorkshops.jpg" alt = "Welcome Title" />';
           }
           elseif (is_tree('productivity-platforms')){
               echo '<img src = "' . $siteUrl . '/images/content_title_productivityPlatforms.jpg" alt = "Welcome Title" />';
           }else{
           }
       ?>
       ```
   
 * It is only working if is_page is true, rather than if it is a child of the parent
   identified in my if statements.

The topic ‘is_tree()’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [jimmyt1988](https://wordpress.org/support/users/jimmyt1988/)
 * Last activity: [15 years, 11 months ago](https://wordpress.org/support/topic/is_tree/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
