Blog > Website Design > WordPress Conditional Tags : If Page Parent & Children
Use this WordPress conditional tag to display content for a certain Page ID and it’s Children.
Example Uses
Use this to display certain JavaScript or CSS for a particular page and it’s children in your header. Load different header images in different pages, Show or Hide Widgets, etc. There are endless possibilities.
The sample code below will display “Apples” for Page ID “10″ and it’s children otherwise show “Oranges”
WP Code
<?php if (is_page(10) || $post->post_parent=="10") { ?>
<p>Apples</p>
<?php } else { ?>
<p>Oranges</p>
<?php } ?>
Where To Put The Code
You can use this tag in or outside the WordPress Loop. Use on WP templates files like single.php, page.php, index.php or your own custom theme templates





December 8th, 2009 at 8:54 am
Excellent post..Keep them coming
Thanks for sharing.
July 13th, 2009 at 7:38 pm
This could be very handy.
I am trying to create/use bespoke templates depending on it’s ‘page’ and it’s ‘children’ there are some ways of doing this, however, to complicated and long winded for me.
Wish it had this functionality built in, considering a lot of people are using WP as a CMS, it should follow some of the basic requirements which are provided by products such as Joomla.
Thanks again for this, fingers crossed.
Thanks,
Gabi.