WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Posts Page Featured Image (15 posts)

  1. joshrodgers
    Member
    Posted 1 year ago #

    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?

    I have tried using: http://pastebin.com/ir5YJm2c and the standard: http://pastebin.com/yZv9yc2W, but neither one works...any ideas?

    Thanks,
    Josh

  2. SNSD Photo
    Member
    Posted 1 year ago #

    do you mean, you want to display featured images from another post ?

  3. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

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

  4. joshrodgers
    Member
    Posted 1 year ago #

    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

  5. joshrodgers
    Member
    Posted 1 year ago #

    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

  6. joshrodgers
    Member
    Posted 1 year ago #

    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

  7. Harrison O.
    Member
    Posted 1 year ago #

    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.

  8. joshrodgers
    Member
    Posted 1 year ago #

    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

  9. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    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?

  10. joshrodgers
    Member
    Posted 1 year ago #

    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

  11. Chip Bennett
    Theme Review Admin
    Posted 1 year ago #

    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?

  12. joshrodgers
    Member
    Posted 1 year ago #

    Chip,

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

    Thanks,
    Josh

  13. Chip Bennett
    Theme Review Admin
    Posted 1 year ago #

    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. :)

  14. joshrodgers
    Member
    Posted 1 year ago #

    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

  15. Chip Bennett
    Theme Review Admin
    Posted 1 year ago #

    I figure it's good, for those of you who still have hair on your head. ;)

Topic Closed

This topic has been closed to new replies.

About this Topic