WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Featured post thumbnail in sidebar (5 posts)

  1. cableghost
    Member
    Posted 2 years ago #

    For whatever reason, when I place the below featured image code in the sidebar, the image displayed is not the featured image of the present post, though it is an image from another post in the same category.

    <?php the_post_thumbnail( '280x280' ); ?>

    I have disabled caching plugin and have cleared cache and cookies. Any suggestions?

    -Scott

  2. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    outside the loop, it is not predictable which thumbnail gets shown; this might depend on secondary codes in your site.
    http://codex.wordpress.org/Function_Reference/the_post_thumbnail

    if you can get the post ID of the current post, you could try using

    <?php $post_id = ?????; echo get_the_post_thumbnail($post_id,'280x280'); ?>

    http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail

  3. Digital Raindrops
    Member
    Posted 2 years ago #

    Check out the default thumbnails sizes

    Try to declare the post as a variable.

    <?php
    global $post;
    if( $post && has_post_thumbnail( $post->ID ) ) {
        get_the_post_thumbnail( $post->ID,'mediuum' );
    }
    ?>

    If you have not changed the Medium thumbnail in the settings then.

    <?php
    global $post;
    if( $post && has_post_thumbnail( $post->ID ) ) {
        get_the_post_thumbnail( $post->ID,array(280,280) );
    }
    ?>

    HTH

    David

  4. cableghost
    Member
    Posted 2 years ago #

    Thanks @atchymyth and David, I'll give each a try and report back.

  5. cableghost
    Member
    Posted 2 years ago #

    @atchymyth- I couldn't figured how to get the current post, so that code didn't work for me

    David- neither code worked for me

    I was able to show it using the following code...

    <?php
    if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
      the_post_thumbnail( array(250,250));
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic