Call Featured Image from Parent Page

I am working on a site and each page group has its own featured image. I am trying to do a conditional statement in the header but not sure how to check for the parent page’s featured image.

<?php 
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
  the_post_thumbnail();
} else{?>

    <img src="<?php bloginfo('template_url')?>/images/BANNER-DEFAULT.jpg"/>


<?php
}
?>

I want it to preform like:

Read More
<?php 
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
  the_post_thumbnail();
} 

if ( ?????? { // check if the parent page has a Post Thumbnail assigned to it.
  the_post_thumbnail();

}else{?>

    <img src="<?php bloginfo('template_url')?>/images/BANNER-DEFAULT.jpg"/>


<?php
}
?>

Can anyone help with this? I am also considering calling in the banner on the page templates and not the header, but I still need a way to call in the featured image on the Parent Page.

Related posts

1 comment

  1. I believe you want something like the following:

    <?php 
    if( has_post_thumbnail( $post->post_parent ) ) { 
      echo get_the_post_thumbnail( $post->post_parent );
    }
    ?>
    

    Calling the_post_thumbnail(); should return the current post thumbnail, whereas using get_the_post_thumbnail(); will allow you to specify the ID, using the parent ID in your case.

    Function Reference for get_the_post_thumbnail()

    Also, if you’re doing this outside of the loop, you’ll need the $post global variable, as seen here.

Comments are closed.