[Resolved] Featured Image & Post Thumbnails — Two Questions

Home Forums Support [Resolved] Featured Image & Post Thumbnails — Two Questions

Home Forums Support Featured Image & Post Thumbnails — Two Questions

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #411289
    Ramesh Srinivasan

    Hi,

    I have two queries about Post thumbnails.

    1. In the customizer, will setting the thumbnail width/height and clicking “Apply..” generate new thumbnail images? Can the system use the original image (but resize it to specified dimension dynamically without saving thumbnail files) as post thumbnail on the home page?

    2. For posts without any feature image set, can GP pick the first image in the post and use it for Post thumbnails? Pls note that I don’t want to set any featured image for those posts, yet want the post thumbnails.

    Thanks Tom/GP Team.

    #411448
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    1. Yes, that option generates new images if no images that size exist. If you just want to resize the image using the original image, you can use some CSS:

    .post-image img {
        max-width: 200px;
    }

    2. GP can’t, but I do believe there are plugins that will do this for you.

    Let me know if you need more info 🙂

    #411456
    Ramesh Srinivasan

    Hi Tom,

    If I understand it correctly, I should leave the image width to 0 and use the CSS instead. Let me try that out.
    [Update: Works perfectly!]

    2. GP can’t, but I do believe there are plugins that will do this for you.

    Ok. Will check if there are any Plugins out there.

    Thanks Tom.

    #411493
    Ramesh Srinivasan

    Tom,

    I found a PHP function that does it. (Src: WPBeginner)

    Can I add the function using “Code Snippets” Plugin so that I don’t have to edit GP’s PHP files.

    <?php if (  (function_exists('has_post_thumbnail')) && (has_post_thumbnail())  ) {
      echo get_the_post_thumbnail($post->ID);
    } else {
       echo main_image();
    } ?>
    #411677
    Tom
    Lead Developer
    Lead Developer

    Unfortunately not – you would need to use some sort of filter in order to do it without altering theme files. I think it’s the post_thumbnail_html filter you would be altering.

    #411735
    Ramesh Srinivasan

    Thanks Tom.

    Solved it partially..

    add_filter('get_post_metadata', function($value, $object_id, $meta_key, $single) {
      
        if (is_home() || is_front_page() || is_archive()){
    	  
      
    	if ($meta_key !== '_thumbnail_id' || $value) {
    		return $value;
    	}
    	  
    	preg_match('~<img[^>]+wp-image-(\\d+)~', get_post_field('post_content', $object_id), $matches);
    	if ($matches) {
    		return $matches[1];
    	}
    	return $value;
    	}
    }, 10, 4);

    That worked.. but it ignores the featured image (if already set) and uses only the 1st image for Post Thumbs. Have to add an If condition somewhere in the code.. Might figure out soon.

    Thanks again for the help Tom.

    #412141
    Tom
    Lead Developer
    Lead Developer

    I would actually go in this direction: https://wordpress.stackexchange.com/a/55494

    Instead of defining a default image, you would need to work your magic to grab the first image in the content.

    #412193
    Ramesh Srinivasan

    Thanks Tom. Will work on that.

    #412456
    Tom
    Lead Developer
    Lead Developer

    No problem 🙂

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.