• Hi,

    I have a strange worpdress issue!

    I have created some custom image sizes using the following code:-

    if (function_exists('add_theme_support'))
    {
    	add_theme_support('post-thumbnails');
    	add_image_size('home-feature', 960, 320, TRUE);
    	add_image_size('news-main', 960, 206, TRUE);
    	add_image_size('news', 49, 87, TRUE);
    }

    All works fine and the images are created at those sizes.

    To call the image for this example in single.php I use the following code:-

    <?php the_post_thumbnail('news-main'); ?>

    But the default thumbnail is called at 150×150!

    Any ideas and I have tried everything.

    Thank you people

Viewing 5 replies - 1 through 5 (of 5 total)
  • Try this.

    <?php if(has_post_thumbnail()) {
            $myThumb = get_the_post_thumbnail($id, 'post-header', array('class' => 'aligncenter'));
            echo $myThumb;
        } ?>

    ‘post-header’ would be whatever image size your looking to display

    Thread Starter obidos

    (@obidos)

    Hello,

    Thank you for your help.

    Still no luck! It’s really strange! All I ever get is the 150×150 thumbnail image showing. No matter how i call the custom image!

    I am doing it within the look:-

    if ( have_posts() ) while ( have_posts() ) : the_post();
    <?php endwhile; // end of the loop. ?>

    I am so confused.

    I use this in my themes ‘inside the loop’ and it works fine, so yours should work!

    <?php if( has_post_thumbnail() ) : ?>
          <div class="aligncenter">
    	<?php the_post_thumbnail( 'news-main' ); ?>
          </div>
    <?php endif; ?>

    Q: You are testing on a new post ‘featured image’ that you have uploaded after adding the code, WordPress will not retrospectivly rebuild the thumbnails?
    Q: You uploaded or set the ‘featured image’ at least 960px wide?
    Q: 960px is wide for an image, is the content area wide enough?

    Test:
    Go to any post, and upload a featured image wider than 960px and check again.

    Test:
    Use the Ajax Thumbnail Rebuild Plugin, and test again.

    HTH

    David

    Thread Starter obidos

    (@obidos)

    Hi David,

    That did not show any images at all ??

    – I have re-uploaded the images after each change in the image size.
    – I have also used a plugin to re-size all images just in case after each image size change.
    – I have created an image wider than 960px wide and my wrapper for the site is 960px wide. All other images work and the static version of the site works. Just building it in to WordPress and having issues.

    I have changed the size of the wordpress thumbnail in settings > media and then it shows my image at the size I want.

    This is not idea as need to be able to set my image sizes.

    Any ideas…I’m lost. I’ve done this on other sites and its worked. This is the latest version of WordPress is that the issue?

    Thank you from a very confused person ??

    I have re-uploaded the images after each change in the image size.

    It will be something really silly when you find what is going wrong, as my code returned no image in the loop then it looks like the featured image size has not been set!

    I am assuming that this is not a child theme but one you are building bottom up?
    Q: In functions.php you have set the post thumbnail Featured Image size?

    add_theme_support( 'post-thumbnails' );
    set_post_thumbnail_size( 960, 320, true );
    add_image_size('home-feature', 960, 320, true);
    add_image_size('news-main', 960, 206, true);
    add_image_size('news', 49, 87, true);

    1: Then when you run the thumbnail rebuild can you see all sizes?

    2: For each post you have set the featured image from the post edit page?

    3: Create a post, upload a brand new image (or rename one), set this ‘new image’ as the ‘featured image’ and view post, see what you have!

    If still no image showing, then post functions.php and the file where you are calling the image to https://pastebin.com and add the links to a reply!

    HTH

    David

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom image sizes’ is closed to new replies.