Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialGonzaloº Caminos
2,231 PointsImages with auto resize?
Works with any image size?Because when i usea an image with different size the portflio post not showing the thumbs correctly.
3 Answers
Craig Watson
27,930 PointsHi Gonzalo,
It may be worth looking into the add_image_size() function. This can be declared in the functions.php as seen below.
<?php
add_image_size( '$name_of_image_size', $width, $height, $crop_to_size = false );
// For your example
add_image_size( 'large_thumbnail', 250, 250, false );
?>
Then you can use that image size in your template with different functions. If you are inside the loop you can use the following.
<?php
the_post_thumbnail_url( 'large_thumbnail' );
?>
If you are outside the loop try using your previous method with the new defined size.
Hope this helps. Crsig
Craig Watson
27,930 PointsHi,
Can you explain a little more about what you require help with please Gonzalo.
Craig
Gonzaloº Caminos
2,231 PointsYes. Im really sorry. I'm triyng to use wp_get_attachment_image_src function but when i use $size with values (ex: width 250, height 250) the function dont resize the image.
I have this code:
<?php
$thumbnail_id = get_post_thumbnail_id();
$size = array('width'=>250,'height'=>250);
$thumbnail_url = wp_get_attachment_image_src( $thumbnail_id, $size, true );
?>
Gonzaloº Caminos
2,231 PointsGonzaloº Caminos
2,231 PointsThanks Craig.