What I would like to do is have my parent page's featured images display, unless a child page has its own featured image, then I would like that image to become the featured image from that page and the rest of its children pages.
-Page 1
-Page 2
-Sub Page 1
-Sub Page 2
-Sub Sub Page 1
-Sub Sub Page 2
So in the example above:
Page 1 and Page 2 would have a featured image set that would display in the header.
Sub Page 1 would inherit Page 2 featured image.
Sub Page 2 would have its own featured image, which sub sub page 1 would inherit.
Sub Sub Page 2 would have its own featured image.
I have tried placing this code in my header, where the image needs to go and it did not draw in any featured images, it just brought in the image slider.:
<?php if ( has_post_thumbnail($post->post_parent, 'pagethumb') ) {
echo get_the_post_thumbnail($post->post_parent, 'pagethumb');
} else {
echo do_shortcode('[rev_slider header-slider-bw]');
} ?>
I also tested to make sure the image was there and working with this code (and it was):
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
Does any one have an advice on how to make this happen? I appreciate any help. Thanks in advance!
the_post_thumbnail
)? Please edit your question, elaborating on what you've tried so far.$post
($post->post_parent
) actually has a featured image? Really sure? By the way,has_post_thumbnail()
accepts only one argument ($post_id
).