How can I set which image size the results thumbnail uses?

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 2 years, 8 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #6636

    aaronjpitts
    Participant

    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

    #6637

    Ernest Marcinko
    Keymaster

    Hi!

    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 :)


    #6638

    aaronjpitts
    Participant

    Perfect, thank you!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.