0

The commented out portion is what I've added to pull the featured image set on the blog page. Without that chunk I'm able to set the image, or pull from the home page's featured image if that page/post doesn't have one. But once I enable the section for 'page_for_posts' everything else goes haywire and it starts outputting an image that isn't set as the feature for anything.

if ( has_post_thumbnail( $post->ID ) ) {
    $imageInfo = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
    $imageUrl = $imageInfo[0];
}
//if ( get_option('page_for_posts') ) {
//      $imageInfo = wp_get_attachment_image_src( get_post_thumbnail_id( get_option( 'page_for_posts' ), 'full' ) ); 
//      $imageUrl = $imageInfo[0];
//}
if ( !has_post_thumbnail( $post->ID ) ) {
    $imageInfo = wp_get_attachment_image_src( get_post_thumbnail_id( '46' ), 'full' );
    $imageUrl = $imageInfo[0];
}

$cssoutput = ".site-header { background-image: url('" . $imageUrl . "'); } \n";

echo 
"<style type=\"text/css\">" . $cssoutput . "</style>";
  • What does get_option( 'page_for_posts') return? And why use if and no else if? – pascalvgemert Jul 1 '14 at 22:55
  • It doesn't return anything anticipated, instead the output on all pages (except those WITH a featured image) is an image not used on any post or page. It should return the featured image of the page designated as the blog page. Originally was using else if before I needed to target the page_for_posts, not sure the best approach to making it happen. – ericakfranz Jul 1 '14 at 23:35
  • You didn't answered my question, what does the get_option('page_for_posts'); returns when you vardump this? – pascalvgemert Jul 2 '14 at 6:09
  • Does the same, it doesn't return any expected results. – ericakfranz Jul 2 '14 at 18:04
  • Can you post the result please? – pascalvgemert Jul 2 '14 at 18:17

Your Answer

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

Browse other questions tagged or ask your own question.