Results 1 to 8 of 8

Thread: Post thumbnails ... either I'm doing something stupid or WordPress is broken

  1. #1
    Ryan's Avatar
    Ryan is offline WordPress Legend
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,801

    Default Post thumbnails ... either I'm doing something stupid or WordPress is broken

    Any ideas why I get the following HTML (ie: incorrect width):
    HTML Code:
    <img width="470" height="304" src="http://domain.com/wp-content/uploads/test.jpg" class="attachment-post-thumbnail wp-post-image" alt="" title="test-470x304[1]" />
    With the following theme code?

    functions.php
    PHP Code:
    add_theme_support'post-thumbnails' );
    add_theme_support'page-thumbnails' );
    set_post_thumbnail_size470304true ); // Normal post thumbnails
    add_image_size'single-post-thumbnail'1509999 ); 
    single.php
    PHP Code:
    the_post_thumbnail'single-post-thumbnail' ); 
    The thumbnail should be 150 pixels wide, not 470 pixels as it should be using the 'single-post-thumbnail' image size ... but it's not



    I'm slowly going insane trying to figure out what I'm doing wrong. I've had this issue about 20x now and by some miracle I occasionally get it to work, but then other times (like now) I can't get it to work at all

  2. #2
    kucrut is offline Hello World
    Join Date
    Apr 2010
    Posts
    11

    Default

    The add_image_size function will only work on newly uploaded images. If wordpress couldn't find the size you specified in the argument for the_post_thumbnail function, I think it will revert to the default you set, which is 470.

    To regenerate the thumbnails you can use this plugin http://wordpress.org/extend/plugins/...te-thumbnails/

  3. #3
    Ryan's Avatar
    Ryan is offline WordPress Legend
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,801

    Default

    No, that's not the problem. It happens on brand new thumbnails. I also tried that plugin but it didn't do anything useful :(

  4. #4
    kucrut is offline Hello World
    Join Date
    Apr 2010
    Posts
    11

    Default

    Maybe you can try and add a new thumbnail size with hard-cropping enabled, say

    PHP Code:
    add_image_size'test-thumbnail',  160160true ); 
    ...regenerate the thumbnails, and try it with the_post_thumbnail function on the frontend.

    Personally I've never had any problem with this feature, so I'm a bit curious :)

  5. #5
    Ryan's Avatar
    Ryan is offline WordPress Legend
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,801

  6. #6
    Ryan's Avatar
    Ryan is offline WordPress Legend
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,801

    Default

    Bingo, I figured out what the problem was!

    The actual code I was using was:
    PHP Code:
    if ( the_post_thumbnail() )
        
    the_post_thumbnail'test-thumbnail' ); 
    The check for whether there was a thumbnail or not was somehow messing with the actual call to the the_post_thumbnail.

    I guess I need to check for the presence of a post thumbnail some other way.

  7. #7
    kucrut is offline Hello World
    Join Date
    Apr 2010
    Posts
    11

    Default

    Ouch, it should be has_post_thumbnail() :)

  8. #8
    Ryan's Avatar
    Ryan is offline WordPress Legend
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,801

    Default

    Oh heck! On looking back through the last few themes I've written which use post thumbnails they're totally riddled with that same check :( I'd been doing some crazy looking hacks to force these things to work as expected. I just kept thinking the thumbnail system was buggy, but no, my code was buggy and I'd been copy and pasting the same bug over and over again :(

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •