• Hi all,

    I’m having a PHP problem where I’m trying to create/echo a thumbnail on the front page. But I want it to automatically resize and crop to a dimension of 250×250. However everything I’ve tried, PHP wise, has not worked for me. The images appear “squished”, so the crop effect does not seem to be working.

    My goal is to crop it from the center as well.

    The site is:
    http://golfdigestplan.wpengine.com/

    I’ve tried these codes, but to no avail:

    <?php echo get_the_post_thumbnail($post_id, 'col1-other-posts'); ?>
    
    <?php echo get_the_post_thumbnail($post_id, 'col1-other-posts’, array( 250, 250, true))
     ); ?>

    Any help would be greatly appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)
  • OK so what you’re doing is to echo the image, but that doesn’t “crop” the image….the image gets cropped/resized as you upload it to WP using the Media Uploader.

    Check your Settings >Media to see what you have set there – those are the sizes that WP will create, and it does it’s best to crop an image in a sensible way to fit those dimensions.

    If none of those are 250 by 250, you can add optional image sizes by following these instructions:

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

    Or there are plugins that add additional “thumbnail” sizes as you upload, giving you more display options.

    I hope this helps 🙂

    Thread Starter robertallen

    (@robertallen)

    Hi Trisha, Thank you for responding.

    I did read somewhere that there is a way to crop images that are already in the media library, so that you don’t have to upload them again.

    My other dilemma is that I have resizing/cropping set on each of the posts (large rectangular images above the header of each post), and I’m afraid this will mess up that portion.

    So, I guess, my problem is I need 2 thumbnails. One that’s very large, and the other that is 250×250 that will fit on the home page.

    I have this in my functions that would add this already…
    add_image_size( 'col1-other-posts', 250, 250, true );

    I must be doing something wrong with the PHP code.

    This is my entire code that does the loop on the home page.

    <ul class="home-col1-other-posts">
    <?php
    $catquery = new WP_Query( '/*cat=6*/&posts_per_page=4&offset=1' );
    while($catquery->have_posts()) : $catquery->the_post();
    ?>
    <li>
    <div class="col1-border"></div>
    
    <div class="col1-thumbnail"><a href="<?php the_permalink() ?>" rel="bookmark"><?php echo get_the_post_thumbnail($post_id, 'col1-other-posts');
    ?></a></div>
    
    <h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
    
    <div class="col1-author">by <?php the_author(); ?></div>
    
    </li>
    <?php endwhile; ?>
    </ul>
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Problem with Cropping Thumbnails’ is closed to new replies.