WordPress.org

Forums

if statement with child pages, and grandchild pages? (3 posts)

  1. chazVnG
    Member
    Posted 4 years ago #

    I have an if statement that brings up specific versions of a header and the sidebar for pages, and it works great for the parent and child pages, but once you hit the grandchild pages it disappears. How would I specify an unlimited depth in the statement?

    Here's a sample of the code:

    <?php } else if ( is_page('360') || is_child_page_of('360') ) { ?>  
    
    		<div class="product_head">
    			HEADER STUFF
    		</div>
    
    <?php } else if ( is_page('363') || is_child_page_of('363') ) { ?>

    Thanks!

  2. Michael
    Forum Moderator
    Posted 4 years ago #

    for instance:

    <?php } else if ( is_page('360') || in_array( 360, get_post_ancestors($post->ID) ) ) { ?>

    http://codex.wordpress.org/Function_Reference/get_post_ancestors

  3. chazVnG
    Member
    Posted 4 years ago #

    YES, that worked.
    THANK YOU.

    I tried looking for what I was trying to do in the codex, and I couldn't figure out how to string it all together. Lifesaver!

Topic Closed

This topic has been closed to new replies.

About this Topic