Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › How can I set which image size the results thumbnail uses?
This topic contains 2 replies, has 2 voices, and was last updated by aaronjpitts 8 years ago.
- AuthorPosts
- November 16, 2015 at 10:19 am #6636
Hi,
In the results listing, the image for the product results uses the full original image which is a complete waste of bandwidth. How can I set it so that $r->image outputs the thumbnail size image for example?
Thanks
November 16, 2015 at 11:01 am #6637Hi!
You have two options in this case.
1. By default the image cropping is disabled to save CPU over bandwith, you can enable it on the Cache Settings submenu: https://i.imgur.com/UIMicxB.png
2. Don’t use the cropping, nor the original images by adding this filter function to your themes functions.php file:
add_filter( 'asp_pagepost_results', 'asp_get_thumb_image', 1, 1 ); function asp_get_thumb_image( $pageposts ) { // Possible values: thumbnail, medium, large, or full $size = "thumbnail"; foreach ($pageposts as $k=>$v) { $url = wp_get_attachment_image_src( get_post_thumbnail_id($v->id), $size ); if ( !empty($url[0]) ) { $pageposts[$k]->image = $url[0]; } } return $pageposts; }
You can change the $size variable in the code to “thumbnail”, “medium”, “large”, or “full”, those are WordPress supported values. I believe the thumbnail is 150×150, the medium is 300×300 and so on..
If you want smaller than 150×150, then the WordPress codex states that an array of dimensions should be given, like so:
$size = array(64, 64);
I’m not sure if that works though.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
November 16, 2015 at 11:16 am #6638Perfect, thank you!
- AuthorPosts
You must be logged in to reply to this topic.