I set 2 crop sizes in the functions.php file.
// Setup Post Thumbnails
// -----------------------------------------------
add_theme_support('post-thumbnails');
add_image_size('imagePost-thumb', 970, 9999,false);
add_image_size('better-thumb', 200, 9999, false);
Then in the appropriate loops we pull one of the thumbnails based on post type.
<?php if ( has_post_thumbnail() ): ?>
<?php $size = (get_post_type() == 'imagepost') ? 'imagePost-thumb' : 'better-thumb'; ?>
<?php get_better_post_thumbnail($size); ?>
<?php endif; ?>
Get better_post_thumbnail() is a function I wrote to get the image and the caption. In it I call the the_post_thumbnail to display the image. Here is that function.
function get_better_post_thumbnail($size) {
$thumbnail_src = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
echo '<div class="thumbnail">';
echo '<a href="' . $thumbnail_src[0] .'">';
the_post_thumbnail($size);
echo '</a>';
if( get_post( get_post_thumbnail_id() )->post_excerpt )
echo '<p class="wp-caption-text">' . get_post( get_post_thumbnail_id() )->post_excerpt . '</p>';
echo '</div>';
}
This works great on my test server. The only problem is when I push it to the live server, the crops don’t work. The images appear as the the correct size because our theme styles them but they are loading at full size.
Per @MathSmith’s suggestion I checked the live server to see if the different image sizes were being created and they are NOT. The test server has all the different files sizes while the live server only has the full size.
We don’t want to load a 1024×1024 picture when it never is displayed larger than 400×400. Of course I could crop the pictures by hand, but my bloggers are all specialists who have a harder time with ‘technology’ and need it to happen automatically, as it should.
Our dev and live setups are identical except for the w3 Total Cache plugin on the live server, but I disabled it and tested the images, with the same results.
Any ideas?
Figured it out! Our live server was missing the GD Image Library. For some reason it was not included in the package we used to instance our server.
I found the tip about the GD lib in this thread from the WordPress support forum. It was three years old, but pointed to the missing library.
We never noticed the fact that the thumbnail size selectors were greyed out because we thought we were taking care of sizing using the Theme Function file.
Thanks @MathSmith and @Wyck