0

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!

1 Answer 1

0

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...

1
  • 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! Commented Sep 5, 2012 at 21:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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