Focusing on my first Wordpress site so I am sure this can be a really fundamental question. I am battling to create a conditional php statement that works a particular action whenever a page is really a child of the parent page.

For instance, as opposed to just indicating one page, as below, Let me specify all pages which have the 'About Us' page being a parent:

<?php if (is_page('About Us')) echo 'Hello World!'; ?>

I have attempted the "child_of" function however it wasn't as straightforward as I'd wished.

After I make use of the below, I recieve a syntax error - most likely just me being unsure of ways to use the function:

<?php if (child_of('About Us')) echo 'Hello World!'; ?>

Any suggestions? Thanks!!

You are getting a mistake because there's no such factor like a child_of() function in WordPress.

child_of() is really a method of searching while using get_pages() function.

$pages = get_pages('child_of=##');

where ## may be the number ID (not the title) from the 'About us' page.

This is actually the final code that labored for me personally - unsure whether it's the best way to do what I am attempting to do, and can publish for the advantage of anybody with my same question.

I've got a group of right hands posts, each specific to some portion of the site (each parent page representing a portion of the site).

I would like parents page and every one of that parent's child pages to drag exactly the same specific right hands column.

This is what Used to do:

<?php 

if (is_page('Page Name 1') || $post->post_parent == '##') {
include (TEMPLATEPATH . '/right-1.php');

} elseif (is_page('Page Name 2') || $post->post_parent == '##') {
include (TEMPLATEPATH . '/right-2.php');

} elseif (is_page('Page Name 3') || $post->post_parent == '##') {
include (TEMPLATEPATH . '/right-3.php');

} elseif (is_page('Page Name 4') || $post->post_parent == '##')
include (TEMPLATEPATH . '/right-4.php');

?>

In which the ## signifies the ID # from the page.

Add the next function for your functions.php theme file:

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
};

You'll be able to make use of the following:

if(is_tree('2')){ // 2 being the parent page id
   // Do something if the parent page of the current page has the id of two
}

Reference: http://codex.wordpress.org/Conditional_Tags