Plugin Author
Ajay
(@ajay)
Hi, the plugin pulls a featured image as the first option and only when this isn’t available does it look to the custom field.
What are the settings for the thumbnail size in the Settings page for Top 10?
What is the setting you have for thumbnail in Settings > Media?
This is the portion of code that pulls the image. It checks if there is a thumbnail image and if this image is below the thumbnail width or height specified in the Top 10 settings page then it pulls out the full image.
$postimage = wp_get_attachment_image_src( get_post_thumbnail_id($result->ID) );
if ( ($postimage[1] < $thumb_width) || ($postimage[2] < $thumb_height) ) $postimage = wp_get_attachment_image_src( get_post_thumbnail_id($result->ID) , 'full' );
$postimage = apply_filters( $filter, $postimage[0], $thumb_width, $thumb_height, $thumb_timthumb );
$output .= '<img src="'.$postimage.'" alt="'.$title.'" title="'.$title.'" '.$thumb_html.' border="0" class="'.$class.'" />';
Thanks, I will look into modifying that bit.
Maybe adding a simple check for empty custom field input would be a good option, or checkbox to manually force it to use that image.
I think the timthumb feature could be easily replaced with WP’s built-in image generation. We specify our image size and you can simply use those values inside:
add_image_size( $name, $width, $height, $crop );
And for any old images, users could use a plugin to force regenerate all images. Just a thought, since its better then timthumb.
Plugin Author
Ajay
(@ajay)
I agree. It’s one of the main things I plan to add into the plugin to remove the need for timthumb.
I was able to figure this out rather easily. I simply added new image size called “popular-img” and changed “full”. That did the trick of pulling new image size as I wanted it.
$postimage = wp_get_attachment_image_src( get_post_thumbnail_id($result->ID), 'popular-img' );
if ( ($postimage[1] < $thumb_width) || ($postimage[2] < $thumb_height) ) $postimage = wp_get_attachment_image_src( get_post_thumbnail_id($result->ID) , 'popular-img' );
$postimage = apply_filters( $filter, $postimage[0], $thumb_width, $thumb_height, $thumb_timthumb );
$output .= '<img src="'.$postimage.'" alt="'.$title.'" title="'.$title.'" '.$thumb_html.' border="0" class="'.$class.'" />';
For anyone that’s interested in modifying it. You just need to update code above inside plugin’s file, and also add this line to create image size inside functions.php.
add_image_size( 'popular-img', 200, 100, true );
200 is width, 100 is height, true is crop.
Note, this only applies to new images uploaded after you add above line. To apply this to old images, you need to use a plugin to force generate all images.
Plugin Author
Ajay
(@ajay)
Viktor,
Thanks for the code. I’ll use this in the plugin and also make the add_image_size more dynamic and related to the image sizes in the Top 10 settings page.