0

The theme I'm using, when browsing a particular category, displays the full featured image (even if it's more than 1000px high), resized to max-width:20%. However, I'd like it to display just a cropped thumbnail that was autogenerated by Wordpress. Here's the relevant code:

while (have_posts()) : the_post();
    $thumb = get_post_thumbnail_id(); 
    $full_thumb = wp_get_attachment_image_src( get_post_thumbnail_id ( get_the_ID() ), 'original') ;

    echo '<article class="search-entry clearfix">';

    if ( $thumb ) {
        $image = hb_resize( $thumb, '', 215, 140, true );
        echo '<a href="'.get_permalink().'" title="'.get_the_title().'" class="search-portfolio-thumb"><img src="'.$image['url'].'" /></a>';
    }

Is this possible?

  • Pass a different size. – GhostToast Nov 19 '14 at 14:01
0

Check out get_the_post_thumbnail()

$image_thumb = get_the_post_thumbnail( get_the_ID(), 'thumbnail');

Here's a more specific example:

while (have_posts()) : the_post();

    echo '<article class="search-entry clearfix">';

    $image_thumb = get_the_post_thumbnail( get_the_ID(), 'thumbnail');

    echo ( $image_thumb ) ? sprintf('<a href="%s" title="%s" class="search-portfolio-thumb">%s</a>', get_permalink(), get_the_title(), $image_thumb) : '';
  • Forgive me for the ignorance, but is this line supposed to replace the one above beginning with $image = hb_resize and then use $image_thumb instead of $image in the following line? – zkvvoob Nov 19 '14 at 17:21
  • I added a more specific example that would replace what you had originally posted. – SkyShab Nov 19 '14 at 17:57
  • No Problemo. Glad I could help. – SkyShab Nov 23 '14 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.