Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have my posts page set to a page named Blog. This is set to use the Template: Default template. So index.php is rendering this page. I want to be able to set the Featured image of this page I've called Blog and have this output at the top of the blog posts page on my site. For every other page on my site I am able to acheive this with

<div style="background-image: url('<?php echo $featured_src[0]; ?>');">

Does anyone have any idea why the featued image would work for page.php but not index.php?

share|improve this question
    
What is the final output (HTML source) on the posts page? Is it an empty inline style attribute? –  jdm2112 May 28 at 18:37
    
this is what I can see when I inspect it: background-image: url(''); but the same image with the same code on page.php give me the image! –  Ciarán May 28 at 18:38

1 Answer 1

when a page is set to be the posts page, then the 'page_for_posts' option will contain the page id of that page; in this case, you can output the featured image with:

if( is_home() && get_option( 'page_for_posts' ) 
 echo get_the_post_thumbnail( get_option( 'page_for_posts' ) );
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.