• I changed the home page to a static page and made a new page my blog page.
    However when i try to set a featured image on the blog page it does not show, it only shows the default header image. I turned the page back to a regular page and the featured image worked. So it must have something to do with being a blog page. Is there a way to have a featured image on a blog page? Or is the only way to control the image by changing the default header image?

    Thanks in advanced

Viewing 15 replies - 1 through 15 (of 15 total)
  • Thread Starter Shadowz

    (@shadowz)

    IS there still no answer?

    Not sure if this will work (Un-tested change) but you could try!

    Find

    if ( is_singular() &&
    	has_post_thumbnail( $post->ID ) &&

    Change to:

    if ( ( is_singular() || is_front_page() || is_home() ) &&
            has_post_thumbnail( $post->ID ) &&

    HTH

    David

    Thread Starter Shadowz

    (@shadowz)

    I see what you mean, though i’m not sure where to find that, do you know what type of file it be in functions.php?

    Also just in case you didn’t know i changed my front / home page to a static page and made my second page the blog page, so you still think it might work.

    Thread Starter Shadowz

    (@shadowz)

    yeah i found it, and tried it. But it did not work, probably because like i said its not a home page or front page its just a secondary page with the blog on it.

    So what would it be called? A blog_page???

    Cause im sure what your saying would work, makes sense.

    Thread Starter Shadowz

    (@shadowz)

    or since i would always want the featured image to show, what about taking out singular so that if it has post thumbnails it shows it?

    But howd i write that out
    if has_post_thumbnail( $post->ID ) &&

    Yeah,

    Reading the post again I see about the home, so single or page should work.

    if ( ( is_singular() || is_page() ) &&
            has_post_thumbnail( $post->ID ) &&

    HTH

    David

    Thread Starter Shadowz

    (@shadowz)

    I tried putting that in, yet it still doesn’t work, i tried re-uploading the image and setting it as the featured. Just to make sure, i should be changing that code in the header.php right? I dont see anything like that anywhere else, but im not for sure.

    Also wondering is it possible to write that line so it shows the featured image no matter what, sorta like if ( has_post_thumbnail( $post->ID ) &&

    Thread Starter Shadowz

    (@shadowz)

    Can anyone help with this, I really dont get it. What adeptis said makes sense. It should be what affects it, but apparently it doesn’t. I even tried useing if (in_the_loop() )

    Its basically a normal page, and i switched my home page to a static page and made this normal page the blog page.

    I was wondering if theres a way to write it so
    “if it has a featured image then display it
    else default header.

    Instead of writing it so
    if its page then show featured image
    else default header.

    if i did it the first way it should work no matter what type of page it is, i just dont know how to write the code to say that.

    here the code i have in my header that target the featured image

    if ( ( is_singular() || in_the_loop() || is_page('7') ) &&
           has_post_thumbnail( $post->ID )  &&
    
    ( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail' ) ) &&
    
    $image[1] >= HEADER_IMAGE_WIDTH ) :
    
    echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
    else : ?>
    
    <img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />
    
    <?php endif; ?>

    Thanks

    Sorry I did not see your reply until this evening, I was not subscribed to the topic.

    if ( has_post_thumbnail( $post->ID )  &&
    
    ( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail' ) ) &&
    
    $image[1] >= HEADER_IMAGE_WIDTH ) :
    
    echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
    else : ?>
    
    <img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />
    
    <?php endif; ?>

    HTH

    David

    Thread Starter Shadowz

    (@shadowz)

    Thanks and thats alright.

    I tried using that code, but its still doesn’t want to work.

    Its really weird there must be something else effecting that particular page type of page i don’t know about.

    Not sure what file effects the blog page though.

    Hi Shadowz,
    have you resolved this issue yet? I have a static home page and my featured images don’t show up on my posts page. Using the twenty-ten theme as well.
    Cheers

    Shadowz – I have set up my site in a similar way to you, and found the solution:

    Use the featured image that you want on your blog page as the main header image – under appearance header. Then, set your different featured image for the home page using the edit page option. This works, and no coding!

    hi Shadowz and others,

    When you define a page as your blog page in the admin panel only the name of that page is used, not the page (and its content or settings like template and featured image) itself. In fact the loop is shown at index.php.
    For this reason $post->ID does not return the ID of the page you defined as your blog page. So has_post_thumbnail( $post->ID ) won’t find the featured image of that page.

    The solution is to get the ID of the page that you defined as your blog page with get_option(‘page_for_posts’) and check if the current page is the one that shows your posts with $wp_query->is_posts_page.
    Here is the code:

    <?php
    // start of additional code
    $page_for_posts = get_option('page_for_posts');
    global $wp_query;
    if ( $wp_query->is_posts_page &&
    	has_post_thumbnail( $page_for_posts ) &&
    	( $image = wp_get_attachment_image_src( get_post_thumbnail_id( $page_for_posts ), 'post-thumbnail' ) ) &&
    	$image[1] >= HEADER_IMAGE_WIDTH ) :
    echo get_the_post_thumbnail( $page_for_posts, 'post-thumbnail' );
    endif;
    // end of additional code
    
    //  Continue with original code. No changes in there...
    if ( is_singular() &&
    	has_post_thumbnail( $post->ID ) &&
    	( $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail' ) ) &&
    	$image[1] >= HEADER_IMAGE_WIDTH ) :
    echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
    else : ?>
    <img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />
    <?php endif; ?>

    Good luck!

    Sorry, I made a little mistake in the if…endif statement. Delete the endif; in the additional code and change the if in elseif in the original code:

    echo get_the_post_thumbnail( $page_for_posts, 'post-thumbnail' );
    // end of additional code
    
    //  Continue with original code. Change if in elseif
    elseif ( is_singular() &&

    @kimbolini

    Nice, simple solution. Why didn’t I think of that?

    That fix will do me for now, I hope…

    Thanks

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘TwentyTen Featured Image Not Showing On Blog Page’ is closed to new replies.