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 created a theme that uses a featured image on every page.

In settings, I have setup my "Posts Page" to be "news"...how do I get the featured image from "news" to display?

The following will display the id of my posts page:

<?php
    $page_for_posts = get_option( 'page_for_posts' );
    echo $page_for_posts;
?>

So I was thinking that this would display the featured image for my posts page:

<?php
    $page_for_posts = get_option( 'page_for_posts' );
    echo get_the_post_thumbnail($page_for_posts, 'large');
?>

But, somehow it doesn't :( Do I need to add this code in the loop or something?

Any ideas?

Thanks, Josh

share|improve this question
    
You need to show us more code. –  Wyck May 18 '12 at 18:03
1  
Note: cross-posted from, and issue resolved in, the wordpress.org support forums. –  Chip Bennett May 18 '12 at 20:07
add comment

closed as too localized by Chip Bennett, Wyck, Brian Fegter, Chris_O, mrwweb Aug 28 '12 at 3:21

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers

You could always do this instead;

$id = get_the_ID();
echo get_the_post_thumbnail($id, 'large');

get_the_ID() gets the ID of the current post/page you are on, and then you pass that into your get_the_post_thumbnail function.

This avoids you needing to use a get_option to retrieve a field from the options table.

share|improve this answer
    
This won't work on page_for_posts. WordPress hijacks the page entirely, and the Loop template tags will return data from the Loop, rather than from the static Page itself. –  Chip Bennett May 18 '12 at 20:31
    
Even to the point of not returning the page ID? Well... that's a hostile takeover. Sounds silly that they don't pass the ID back, regardless of their hijacking. In that case revert to get_option( 'page_for_posts' ). –  userabuser May 18 '12 at 20:39
add comment
up vote 0 down vote accepted

I feel like such an idiot!! I was trouble-shooting this last night and I guess I removed the featured image for the news page...so, of course, the image wasn't showing up!

I added the featured image and the following code:

<?php if(is_home()) { ?>
    <?php
        $page_for_posts = get_option( 'page_for_posts' );
        echo get_the_post_thumbnail($page_for_posts, 'large');
    ?>
<?php } ?>

Now, everything works as expected (Note: cross-posted from, and issue resolved in, the wordpress.org support forums.)

share|improve this answer
add comment

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