Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have used '0' == $post->post_parent successfully in my templates to target top level pages.

However, I cannot seem to target all pages EXCEPT top level pages:

    <?php 
    if ( '0' !== $post->post_parent ) { 
        include 'siblings.php'; 
    } 
    ?>               

Using the code above, the file is still included in top level pages.

Note, I can get it working using the code below, but I want to keep it flexible and not have to specify IDs:

    <?php 
    if ( !is_page( array( 8, 10, 12 )) && (is_tree(8) || is_tree(10) || is_tree(12)) ) { 
        include 'siblings.php'; 
    } 
    ?>

Hope someone can help!

share|improve this question

1 Answer 1

Try this:

  <?php 
    if ( '0' != $post->post_parent) { 
        include 'siblings.php'; 
    } 
    ?> 

!== refers to an exact type match too. So your code doesn't work because the post id is stored as an integer. != will disregard the fact that you are comparing a string to a number.

Hope this helps.

You could also simply use the integer 0 in place of '0' in the first place...

share|improve this answer
    
Thanks Douglas, but that made no difference. However, I think this problem is more complex than originally thought! You see, I can use if ( '0' != $post->post_parent) to include other files no problem. Could be something dodgy in the included file? Oh dear! –  Caroline Elisa Sep 5 '12 at 21:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.