WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Why is it impossible to get thumbnail when image not attached to post? (16 posts)

  1. Alkorr
    Member
    Posted 1 year ago #

    This is a HUGE dysfunction in WP... I've been trying to get the thumbnail from the first image in my post which is not attached to this post because it has already been uploaded (therefore attached) to a previous post and I simply can't.

    This means I have a 'books' category and when I insert the 'book_new.jpg' image to my posts, the image is showing in the post of course but since it's not attached to it, I can't get the thumbnail and so I can't show the thumbnail on my homepage... (any function like wp_get_attachment_image would work since the image MUST be attached to the post...).

    Totally weird, a real dysfunction obviously. WordPress is amazing, really but when you use it as a CMS, not having the ability to re-use already attached images into other posts and show the thumbnail is beyond understanding.

    I've read on WP.com:

    If you’d like to use the attached image with another post, please try uploading it again directly from the Media Library. Please note that the newly uploaded image’s URL will be different.

    I can't imagine uploading the same image multiple times, each time I want to show a thumbnail!!

    I'm not the only one pointing out this problem. It would be so great if a solution was available!

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    It's not a dysfunction - huge or otherwise. You're simply not approaching this in the right way. For example, have you made this image the featured image for that Post?

  3. Alkorr
    Member
    Posted 1 year ago #

    Hi esmi, thanks for your reply.

    I am approaching this the way it is the more logical: I insert an image in a post, and I use it again, as often as I want. This how it should work.

    Now if I have to use a featured image, in each on my post instead of inserting the image within my post, I will. But still, will I be able to get the thumbnail of that featured image with a function?

    It looks way more complicated but if it's the only solution, it's better than nothing!

  4. esmi
    Forum Moderator
    Posted 1 year ago #

    Yes. Have a look at the_post_thumbnail and get_the_post_thumbnail.

  5. Alkorr
    Member
    Posted 1 year ago #

    Ok, so I need to edit all my posts and modify them one by one to make the image from the post a featured image, right? But then, I will be able to get the thumbnail of this image for all the posts that will have this image featured, right? No more problem with using an image which is already attached to a previous one?

  6. esmi
    Forum Moderator
    Posted 1 year ago #

    If your theme's template files do not already support the_post_thumbnail() (and most do these days), then - yes - you'll need to add support.You may also need to add add_theme_support( 'post-thumbnails' ); to your theme's functions.php.

    Once all that is done, you can select a featured image from your existing Media Library via Add Media when editing/creating a Post. No attachment necessary. :-)

  7. Alkorr
    Member
    Posted 1 year ago #

    Ok, will do that. So I will also have to add the function in my single.php to show the featured image withing my post. But what if I want to show the featured image either on the right or the left side of the text? How can I add the class to do so?

    And last but not least, if there is not featured image, how can I show a default one instead?

    Thanks for your help :)

  8. esmi
    Forum Moderator
    Posted 1 year ago #

    what if I want to show the featured image either on the right or the left side of the text?

    Depending upon how your theme's templates are put together, you may be able to do this with pure CSS.

    if there is not featured image, how can I show a default one instead?

    Something like:

    if( get_the_post_thumbnail() ): the_post_thumbnail();
    else:?>
    <img src=" <?php echo get_stylesheet_directory_uri(); ?> /images/default.png" width="xx" height="yy" alt="" />
    <?php endif;?>

    shoukd work assunging:

    a) you're in the Loop
    b) your default image is called default.png & is stored in your theme's images sub-folder.

  9. Alkorr
    Member
    Posted 1 year ago #

    Fantastic esmi, really!

    As for the CSS, I don't know where I can specify the class I want to use to either float the featured image to the right or to the left, depending of the post. When I click on the featured image, there is no field for CSS so far.

  10. Alkorr
    Member
    Posted 1 year ago #

    I mean a way to choose float right or left from the post. No default floating.

    Didn't find anything so far...

  11. esmi
    Forum Moderator
    Posted 1 year ago #

    Try using Firefox with the Firebug add-on for this kind of CSS troubleshooting. Or use whatever developer tool is available in your web browser.

  12. Alkorr
    Member
    Posted 1 year ago #

    Thanks esmi but it doesn't have anything to do with Firebug but strictly with WordPress.

    I made a search on Google and couldn't find anything about it. You have no possibility to choose to either float the featured image to the right or the left when setting it. Unlike any other image you put in your post.

    Keep searching...

  13. esmi
    Forum Moderator
    Posted 1 year ago #

    You have no possibility to choose to either float the featured image to the right or the left when setting it.

    Because that is handled by your theme's CSS.

  14. Alkorr
    Member
    Posted 1 year ago #

    No, esmi, it's not. I can handle the featured to float right or left in my theme's CSS but that's not what I'm looking for.

    I want to be able to choose for a specific post to float the featured image right, and for another one, to float it left. Which means I could do that from the admin but there is no way to add any CSS directly from the post for a featured image (but it is when inserting an image within a post...).

    Apparently, that's something impossible using a featured image.

  15. esmi
    Forum Moderator
    Posted 1 year ago #

    There's no way to do this in WordPress itself.

  16. Alkorr
    Member
    Posted 1 year ago #

    Thanks a lot for your help esmi.

    But now I'm stuck with the featured image and I can't manage it as I would be able to do if I used the first image inserted into the post.

    I may have approached this the wrong way at first but WP making mandatory to use a featured image to use thumbnail (not mentioning attached images) is way more complicated. Like this thread proves it.

    Anyway, by default all the featured images will float left since I can't choose from the Admin. Not very fexible but now I edited all my posts, I'll have to stick with it!

    Thanks again esmi ;)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags