• Jenn

    (@jenny_jane)


    I have some code in place that displays a header image depending on which section you are in. I have it working so that when you are on a child page, the header image of the parent page displays. But I’m having trouble getting the section’s header image to appear on grandchild pages.

    I tried using get_post_ancestors to acheive this, but I must not be using it right because the correct header image doesn’t appear on grandchild pages.

    Here’s what I have:

    <?php 
    
    	$ancestors = get_post_ancestors($post->ID);
    
    	if ( is_page('about-us') || $post->post_parent == '24' || $ancestors == '24' ) {
    		$bannerimg = 'about-us-header.jpg';
    	} else {
    		$bannerimg = 'default-image.jpg';
    	}
    ?>
    <img src="<?php bloginfo('template_url'); ?>/images/<?php echo $bannerimg; ?>" />

    Does anyone have any advice for me? Thanks in advance.

  • The topic ‘Header image for all grandchild pages of top most parent’ is closed to new replies.