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

Posted by : Dinusha | Apr 24, 2009

4 Responses to “WordPress Conditional Tags : If Page Parent & Children”

  1. JaRo Says:
    4

    Thanks a lot

  2. HABA Baby Says:
    3

    I notice a fantastic development in your writing, I would like to have in touch. Maintain the good operate! Your composing is really inspirational for someone who is new to this type of stuff.

  3. Scripto Says:
    2

    Excellent post..Keep them coming :) Thanks for sharing.

  4. Gabi Says:
    1

    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.

Leave a Reply

Name (required)

Mail (will not be published) (required)

Website

Blog Categories

Posts + Podcasts

Podcast Feeds

Design Portfolio

Design Services