I recently added 270x270px gallery and post thumbnails to WPFolio Two. They look damn nice in columns of three in the portfolio categories. While working on this, I found that WP's thumbnail/image attachment functions are not so well documented, so I wanted to be sure to share what I figured out. Here I'll go over the code to change the thumbnail size with
add_image_size, then grab a post's first attachment and turn that into the thumbnail, and finally filter the gallery shortcode to change gallery thumbnail sizes.
NOTE : this is a relatively verbose tutorial, so you can just download the code here if you like.
First download the Regenerate Thumbnails plugin. Run it whenever you want to see your changes, mainly when you are wondering why the thumbnails are not being cropped.
Everything goes in
functions.php. First, you'll need to add theme support for thumbnails, set the thumbnail size, and add a custom image size for the generated thumbnails. That happens like this:
WP generates a special URL for resized post thumbnail images, for example, the URL of a 150 x 150 thumbnail of myimage.jpg would be
../wp-content/uploads/2011/09/myimage-150x150.jpg. This can be changes in Settings/Media. The function
add_image_size('wpf-thumb', 270, 270, true), essentially does the same thing, but is adding a new image size called 'wpf-thumb' rather than changing the 'Thumbnail' size. The 'true' sets cropping mode to true. If false, your images will retain their original proportions i.e. will not be even squares. Later, we will apply 'wpf-thumb' to an image url for the post thumbnails created from attachments.
Read More →