Try:
false != $post->post_parent
I’m pretty sure that, when TRUE, $post->post_parent
returns an ID, rather than TRUE.
Thanks Chip,
but this not work, too!
First, upon further investigation, it appears that if ( $post->post_parent )
should work.
Also, I think you have a PHP boolean syntax error.
This:
<?php if ( is_active_sidebar( 'right-sidebar' ) or $post->post_parent ) : ?>
should instead be this:
<?php if ( is_active_sidebar( 'right-sidebar' ) || $post->post_parent ) : ?>
In other words, use the boolean operator ||
instead of or
.
Thanks Chip for the correction and the proposal! But still does not work!
here’s the entire code
[Code moderated as per the Forum Rules. Please use the pastebin]
Hmm… re-reading your original post, your second conditional is intended to be true if the current Page has children, right?
In which case, $post->post-parent
won’t get you there, because it indicates that the current Page is a child Page.
Try instead using get_pages()
: http://codex.wordpress.org/Function_Reference/get_pages
e.g.:
<?php if ( is_active_sidebar( 'right-sidebar' ) || get_pages( array( 'child_of' => $post->ID ) ) ) : ?>
(Edited to correct get_pages() argument)
Hi Chip,
U are WordPress nindja!
<?php if ( is_active_sidebar( 'right-sidebar' ) || get_pages( array( 'child_of' => $post->ID ) ) ) : ?>
That is work for parent page!
I add code from previews post, like this:
<?php if ( is_active_sidebar( 'right-sidebar' ) || get_pages( array( 'child_of' => $post->ID ) ) || $post->post_parent) : ?>
And now it’s work for parent and child pages, too!
Thanks again!
Best Regards!
Glad to help! 🙂
(p.s. be sure to mark the topic as “Resolved” to facilitate others with similar issues finding a solution.)