• Resolved Rob Cubbon

    (@robcub)


    Hello, I am creating a theme where there will be a series of logos along the footer that I would like to be Featured Images of a particular blog category.

    So in functions.php I have:

    add_theme_support( 'post-thumbnails' );
    set_post_thumbnail_size( 50, 50, true );

    And in the footer.php I have:

    <?php query_posts('cat=4&showposts=5'); ?>
    			<?php while( have_posts() ) : the_post(); ?>
    				<?php if(has_post_thumbnail()) { ?>
    				<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
    					<?php the_post_thumbnail(array(50,50)); ?>
    				</a>
    				<?php } ?>
    			<?php endwhile;?>

    Which seems to work quite well if the logo is squared shape. However, if it is a horizontal rectangle you only get the middle section of the logo.

    Is there anyway to just specify the width in a Featured Image and let the height size proportionately?

    Or is there a better way of doing this?

Viewing 5 replies - 1 through 5 (of 5 total)
  • yes, when setting up the dimensions instead of 50, 50 make the width your set size, and the height some giant number.

    for instance I use

    add_image_size( 'shop-single-image', 450, 9999 ); //Shop Single Product Image

    for one of my thumbnail sizes. This sets the width at 450px, but allows the height to go up to 9999px.

    Thread Starter Rob Cubbon

    (@robcub)

    I’m sorry Rev. Voodoo, I tried

    add_theme_support( 'post-thumbnails' );
    set_post_thumbnail_size( 50, 9999, true );

    In functions.php, the crop came out wrong again whether it was array(50,50) or array(50,9999) in footer.php.

    And I tried

    add_image_size( 'shop-single-image', 450, 9999 );

    with and without
    set_post_thumbnail_size( 50, 50, true );

    in functions.php and that killed the site.

    I’m obviously getting something wrong with my php here.

    it looks like you may be getting some stuff confused here…..
    if you have this in functions.php:

    set_post_thumbnail_size( 50, 50, true );

    you don’t need this in your footer:

    <?php the_post_thumbnail(array(50,50)); ?>

    just:

    <?php the_post_thumbnail(); ?>

    reason being, you set the size in functions.php, then using that array in footer.php you set the same size as in functions.php. Really, set the size in functions, or in the array.

    As for my code with add image size, it goes in functions, under your initial setup. So like this:

    add_theme_support( 'post-thumbnails' );
    set_post_thumbnail_size( 50, 50, true );
    add_image_size( 'bigger_image', 450, 9999 );

    then, in footer.php you would call:

    <?php the_post_thumbnail(); ?>

    to get the 50×50 image, and

    <?php the_post_thumbnail('bigger_image'); ?>

    to get the larger one we set up in functions.php

    Now, I don’t believe that changing the size of your thumbnails in your code regenerates your existing thumbnails. So once you get the code right, you may need to make a new post to test. (I’m unsure about this though)

    Thread Starter Rob Cubbon

    (@robcub)

    Awesome ??

    You don’t have to create a new post. The old thumbnails re-sized by this method. Amazing!

    Thank you so much, Rev. Voodoo.

    Cool, I wasn’t sure so thanks for reporting back! Glad you got it!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Sizing Featured Images’ is closed to new replies.