Title: is_tree problem
Last modified: August 19, 2016

---

# is_tree problem

 *  [inky-dan](https://wordpress.org/support/users/inky-dan/)
 * (@inky-dan)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/is_tree-problem/)
 * Hey all,
 * I’m having some trouble getting the is_tree() function to work. I’ve set it up
   as the codex, and other pages, state, but the values which it to me are always
   from the else statement of my if argument, regardless of which page i go to.
 * I’m running my wp installation on a subdirectory of my localhost, could that 
   be a problem?
 * Here’s what I’ve put into 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
       	if(is_page()&&($post->post_parent==$pid||is_page($pid)))
                      return true;   // we're at the page or at a sub page
       	else
                      return false;  // we're elsewhere
       }
   
       ?>
   
       <?php
   
       if (is_tree("374")) { // if root page is the products page (change id as appropriate)
   
       	$selection = 'selection_products';
       	$logoimg = 'images/site/products_logo.gif';
   
       } elseif (is_tree("148")) { // if root page is the shop section
   
       	$selection = 'selection_shop';
       	$logoimg = 'images/site/shop_logo.gif';	
   
       } elseif (is_tree("382")) { // if root page is the help section
   
       	$selection = 'selection_help';
       	$logoimg = 'images/site/help_logo.gif';	
   
       } else {
   
       	$selection = 'selection_home';
       	$logoimg = 'images/site/home_logo.gif';	
   
       }
   
       ?>
       ```
   
 * All help appreciated!
 * nb:
    When I get this working I want to make the modification suggested by [Marty Tomly](http://www.web-templates.nu/2008/09/07/get-depth-like-is_child-is_grandchild/)
   so that grandchildren are also selected, but that’s not an issue for now.

Viewing 1 replies (of 1 total)

 *  Thread Starter [inky-dan](https://wordpress.org/support/users/inky-dan/)
 * (@inky-dan)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/is_tree-problem/#post-1271980)
 * *bump*
 * sorry, I don’t like to bump but I still need help. Any clues?
 * thanks

Viewing 1 replies (of 1 total)

The topic ‘is_tree problem’ is closed to new replies.

 * 1 reply
 * 1 participant
 * Last reply from: [inky-dan](https://wordpress.org/support/users/inky-dan/)
 * Last activity: [16 years, 7 months ago](https://wordpress.org/support/topic/is_tree-problem/#post-1271980)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
