Wordpress php: Way to test if pages are children of a parent page?

Posted by Erykan on Stack Overflow See other posts from Stack Overflow or by Erykan
Published on 2009-05-21T03:07:06Z Indexed on 2010/06/06 12:32 UTC
Read the original article Hit count: 183

Hi - Working on my first Wordpress site so I'm sure this is a really basic question. I'm struggling to write a conditional php statement that performs a certain action when a page is a child of a parent page.

For example, rather than just specifying one page, as below, I'd like to specify all pages that have the 'About Us' page as a parent:

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

I've tried the "child_of" function but it wasn't as straightforward as I'd hoped.

When I use the below, I get a syntax error - probably just me not knowing how to use the function:

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

Any suggestions? Thanks!!

© Stack Overflow or respective owner

Related posts about php

Related posts about Wordpress