0

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?

2
  • What is the final output (HTML source) on the posts page? Is it an empty inline style attribute? – jdm2112 May 28 '14 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 '14 at 18:38
0

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' ) );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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