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:
<?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.
I believe you want something like the following:
Calling
the_post_thumbnail();
should return the current post thumbnail, whereas usingget_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.