WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Posts Page Featured Image

[Resolved] Posts Page Featured Image

Viewing 14 replies - 1 through 14 (of 14 total)
  • do you mean, you want to display featured images from another post ?

    Moderator Michael

    @alchymyth

    Forum Moderator

    you can post up to 10 lines of code directly in the forum – just make sure to mark them using the code button, or wrap the code in backticks – see http://codex.wordpress.org/Forum_Welcome#Posting_Code

    try:

    <?php if( is_home() && get_option('page_for_posts') ) :
    echo get_the_post_thumbnail(get_option('page_for_posts'));
    endif; ?>

    or the same as a one-liner:

    <?php if( is_home() && $id = get_option('page_for_posts') ) echo get_the_post_thumbnail( $id ); ?>

    alchymyth,

    I’m sorry, neither one of those work 🙁

    I left them as is, I changed page_for_posts to be news, News, or 113 and the code still didn’t work 🙁

    Any Ideas…Thanks,
    Josh

    blacklizt,

    Nope…I have a featured image assigned to a page called “news”. I did this by going to: Settings > Reading > and choosing “news” in the Posts Page dropdown.

    Thanks,
    Josh

    Ok,

    So, after looking into the issue, I wrote the following:

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

    The only problem is that my ID echo’s just fine, but it still doesn’t display the thumbnail 🙁

    Thanks,
    Josh

    If possible, paste the whole code from the template you are using for the “news page” into pastebin.com, also the code from functions.php. That may help pinpoint the problem.

    Ok,

    Keep in mind I didn’t write this code, I’m just tweaking it for a friend of mine: index.php…http://pastebin.com/YbdFNZ3j functions.php: http://pastebin.com/NP55A2bD

    Thanks,
    Josh

    Moderator Michael

    @alchymyth

    Forum Moderator

    where in index.php would you have the code for the post thumbnail?

    is it sthis line 11:

    <div id="photo"><?php echo get_the_post_thumbnail( $post_id); ?></div>

    if you – just as a test – switch to the default settings (‘your latest posts’) under ‘settings’ -> ‘reading’, does the thumbnail show in the ‘news’ page?

    alchymyth,

    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…THANKS so much for your help!

    Josh

    Chip Bennett

    @chipbennett

    Theme Review Admin

    If I’m understanding you correctly, this will work:

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

    Question:

    In what template file have you placed this code?

    Chip,

    I have this code in index.php and everything is working great!

    Thanks,
    Josh

    Chip Bennett

    @chipbennett

    Theme Review Admin

    Glad to hear it!

    P.S. another good sanity check here would have been to use has_post_thumbnail(), e.g.:

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

    Might have saved a few pulled hairs. 🙂

    Chip,

    You’re right…those are good suggestions that I will definitely put to good use in the future (I like the hair on my head…lol)!!

    Thanks,
    Josh

    Chip Bennett

    @chipbennett

    Theme Review Admin

    I figure it’s good, for those of you who still have hair on your head. 😉

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘[Resolved] Posts Page Featured Image’ is closed to new replies.