WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] the_post_thumbnail returning wrong size images (5 posts)

  1. catnhat
    Member
    Posted 3 years ago #

    I have thumbnails setup to 85x85 cropped.
    I have rebuilt thumbnails with 2 different plugins with the same result.

    The thumbnail images are properly changed and cropped to 85x85.

    However when I use <?php the_post_thumbnail('thumbnail'); ?>
    it returns results in the 85x85 image being stretched to 85x57 or 56x85.

    In short, the thumbnails are being created properly but displayed as if they are not cropped.

    Any ideas?

  2. esmi
    Forum Moderator
    Posted 3 years ago #

    Try adding:

    set_post_thumbnail_size( 85, 85, true );

    to your theme's function.php file

  3. catnhat
    Member
    Posted 3 years ago #

    I am already using this with other dimensions for other purposes.

    so I tried adding my own with add_image_size('squareThumb', 85, 85, true);

    It did the same thing as thumbnails.

  4. catnhat
    Member
    Posted 3 years ago #

    Am I the only one with this issue?

  5. catnhat
    Member
    Posted 3 years ago #

    I ended up creating a function in my child theme to take car of this. and then called the function instead of using the post thumbnail function.

    the code for the function looks like this:

    <?php
    function fc_rel_thumb($postid=0, $size='squareThumb', $attributes='') {
    	if ($postid<1) $postid = get_the_ID();
    	if ($images = get_children(array(
    		'post_parent' => $postid,
    		'post_type' => 'attachment',
    		'numberposts' => 1,
    		'post_mime_type' => 'image', )))
    		foreach($images as $image) {
    			$thumbnail=wp_get_attachment_image_src($image->ID, $size);
    			?>
    <img src="<?php echo $thumbnail[0]; ?>" <?php echo $attributes; ?> />
    <?php
    		}
    	else {
    		echo '<img src=' . get_bloginfo ( 'stylesheet_directory' );
    		echo '/images/no-attachment.gif>';
    	}
    
    }
    add_image_size('squareThumb', 85, 85, true);
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic