• Resolved double_dd

    (@double_dd)


    Hi,

    I’m creating previous and next buttons for each single blog post. So I have returned the thumbnails for each previous and next post.

    The issue is I want to hard crop the thumbnails returned to a specific size due to some featured images being portrait vs landscape.

    1st version of my code:

    $prevPost = get_previous_post('true');
    $prevthumbnail = get_the_post_thumbnail($prevPost->ID, array(300,300, true));

    The portrait thumbnail image assigned to one of the posts is being resized but only on one edge. It’s not turning into a 300×300 square with a hard crop.

    Can this crop be made here? or does it have to happen when the thumbnail is added to the post (via adding a new image size)?

Viewing 1 replies (of 1 total)
  • Thread Starter double_dd

    (@double_dd)

    UPDATE

    It looks as though you can’t crop on the fly (or at least I couldn’t make this work).

    So my code in my functions.php file is as follows:

    add_theme_support( 'post-thumbnails' )//this adds thumbnail support;
    add_image_size( 'prevnextimage', 400, 300, true );//this adds a new image size

    In my single.php file the code is as follows:

    <?php $prevPost = get_previous_post('true');
    $prevthumbnail = get_the_post_thumbnail($prevPost->ID, 'prevnextimage'); ?>

    I had to then use the regenerate thumbnail plugin here: https://wordpress.org/plugins/regenerate-thumbnails/

Viewing 1 replies (of 1 total)

The topic ‘get the post thumbnail sizing’ is closed to new replies.