re-cropping the_post_thumbnail
-
Hello, I am trying to get a page to “dynamically” crop a thumbnail. Not sure if I’m explaining it correctly. Maybe some code will help…
functions.php
add_image_size( 'siteorigin-unwind-1140x200-crop', 1140, 200, true ); add_image_size( 'siteorigin-unwind-1140x200-crop-top', 1140, 200, array( 'center', 'top' ) ); add_image_size( 'siteorigin-unwind-1140x200-crop-bottom', 1140, 200, array( 'center', 'bottom' ) );
content-single.php
<?php $thumb_type = get_post_meta($post->ID, 'banner_crop', true ); if ( !empty($thumb_type) ) { if ( $thumb_type == "top" ) { the_post_thumbnail( 'siteorigin-unwind-1140x200-crop-top', array( 'class' => 'aligncenter' ) ); } elseif ( $thumb_type == "bottom" ) { the_post_thumbnail( 'siteorigin-unwind-1140x200-crop-bottom', array( 'class' => 'aligncenter' ) ); } else { the_post_thumbnail( 'siteorigin-unwind-1140x200-crop', array( 'class' => 'aligncenter' ) ); } ?>
So as you can see, I’ve defined three different custom image sizes. In my single page, I am reading meta data from custom fields. If the value returned is “top”, then use the crop that aligns center and top. If it’s “bottom”, then use the crop that aligns center and bottom. It works on the first try. But when I change the metadata value and refresh the page, nothing happens. It’s stuck with the first result. I tried deleting the image and re-uploading it. But, that did nothing. What am I doing wrong?? ??
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘re-cropping the_post_thumbnail’ is closed to new replies.