• Resolved parisology

    (@parisology)


    I have a site with about 1000 catalog items, and about 200 foogalleries. There is an index page where I list some of the items with a thumbnail image. I use the foogallery “featured_attachment” api to get the thumbnail image url. Problem is that the image url retuned is for the full size image, and I don’t want client side image sizing for a hundred images or more. I want the 150×150 image that wordpress creates when uploading media images. So I have been hacking the url with str_replace to get the 150×150 images. Obvious cludgy technique here… I would like a foogallery api like “featured_attachment_thumbnail” or something like that. Are you familiar with a scenario like this and have any suggestions?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author bradvin

    (@bradvin)

    hi @parisology

    At the moment, you are calling the featured_attachment method on the gallery object, which returns an instance of FooGalleryAttachment (found in class-foogallery-attachment.php). This object has a url property which is probably what you are using.

    The FooGalleryAttachment “wraps” the WP attachment, so you can get to the attachment ID by using the ID property. You can then get the thumbnail using the built in WP methods. Something like this:

    
    // assume you already have an instance of $gallery which the current FooGallery object
    $foogallery_attachment = $gallery->featured_attachment();
    $attachment_id = $foogallery_attachment->ID;
    $thumbnail_info = wp_get_attachment_image_src( $attachment_id, 'thumbnail' );
    echo $thumbnail_info[0];
    

    Alternatively, if you want a different/custom size thumb, then you can use FooGallery’s built in thumb engine:

    
    // assume you already have an instance of $gallery which the current FooGallery object
    $foogallery_attachment = $gallery->featured_attachment();
    
    $args = array(
      'width' => 200,
      'height' => 200
    );
    
    $attr = foogallery_build_attachment_html_image_attributes( $foogallery_attachment, $args );
    
    echo $attr['src'];
    

    In both of these code snippets, the thumbnail URL will be output

    Thread Starter parisology

    (@parisology)

    wp_get_attachment_image_src is what I needed. Thanks this works!

    Thread Starter parisology

    (@parisology)

    I did notice one thing. If a gallery exists, but has no images, the image returned is not the placeholder image. So I have reverted to my cludge technique.

    Plugin Author bradvin

    (@bradvin)

    If the gallery has no images, then the attachment_id will be null or zero. In that case, do not call wp_get_attachment_image_src

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Foogallery thumbnails’ is closed to new replies.