• Hello,

    I have recently discovered WordPress new feature the_post_thumbnail

    I now use it quite extensively for the site I am building but some aspects leave me totally puzzled : according to where I place the thumbnail on my site (home, sidebar, category page…), the size seems NOT to be controlled by the same attributes or parameters, and I had a hard time trying to understand it all.

    ? Sometimes I have to use the php (array) function. But it sometimes will not work, for reasons beyond my grasp. Besides, it makes the thumbnail square (I have tested several values) when I sometimes want it to keep width/height proportion.

    ? Sometimes I have to edit the [ .wp-post-image ] CSS class, along with [img.wp-post-image]

    ? Sometimes, nothing works but the [ .attachment-thumbnail ] CSS class does work.

    In short, the whole stuff drives me crazy.

    ? Let me add that I tried several options, such as
    the_post_thumbnail('thumbnail');
    which NEVER did the trick but rather displays the full size image on my site, whatever I try. This particular example was solved using the [ .attachment-thumbnail ] CSS class.

    ? And the codex pages are of little help since half of the stuff does not work (at least with me).

    ? Could the WP scholars sort all this out ?

    Example of my own CSS :

    .wp-post-image {margin: 2px 8px 0 0 }
    img.wp-post-image {border:1px solid #f8f8f8; float: left;}
    .attachment-thumbnail {width:100px;height:auto}

    By the way, I did add to functions.php the necessary

    add_theme_support( 'post-thumbnails' );

Viewing 3 replies - 1 through 3 (of 3 total)
  • it makes the thumbnail square (I have tested several values) when I sometimes want it to keep width/height proportion.

    Use:

    if ( function_exists( 'set_post_thumbnail_size' ) ) {
    	set_post_thumbnail_size( THUMB_WIDTH, THUMB_HEIGHT ); // box (proportional) resize mode
    }

    in functions.php. If you want a hard crop (fixed/not proportional) use:

    set_post_thumbnail_size( THUMB_WIDTH, THUMB_HEIGHT, true );

    THUMB_WIDTH and THUMB_HEIGHT are the image dimension in pixels (eg 100 for 100px) but I sometimes set these to equal to options set in Settings/Media using:

    define('THUMB_WIDTH', get_option('thumbnail_size_w'));
    define('THUMB_HEIGHT', get_option('thumbnail_size_h'));

    https://markjaquith.wordpress.com/2009/12/23/new-in-wordpress-2-9-post-thumbnail-images/ is a nice summary of what you can do with post thumbnails.

    The post @esmi gave the link to is also how I learned to use the thumbnails. These two posts got me sorted on doing a few extra things with the thumbnails….between the 3 posts, good info

    https://www.kremalicious.com/2009/12/wordpress-post-thumbnails/

    https://justintadlock.com/archives/2009/11/16/everything-you-need-to-know-about-wordpress-2-9s-post-image-feature

    Hello!

    I need to do something like this:

    if ( has_post_thumbnail() ) {
    the_post_thumbnail();
    } else {
    $thumb = getFirstImagefromPostandResize ();
    <strong>set_post_thumbnail($thumb);</strong>
    the_post_thumbnail();
    }

    getFirstImagefromPostandResize it’s ok code already available based on plugin.

    I need to know how to do for this kind of function in wordpress : set_post_thumbnail($thumb)

    in order to store my automatically generated thumbnail

    and reuse it transparently with the_post_thumbnail() without passing by manual GUI uploader (set thumbnail);

    Do you know how to do it? which function i have to call in wordpress?

    thank you very much for your answers.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘the_post_thumbnail’ is closed to new replies.