• Resolved dansz

    (@dansz)


    I love this plugin. I use it with almost every project – but I’m always running into issues handling images.

    I’ve got a project where I’m using image_advanced for users to populate a jquery slider on the front end. Each uploaded image shows up as a slider image (large) and an thumbnail (thumbnail).

    Can I pull values for both sizes from a single array? Or is there a comprehensive way of merging the large array with the thumbnail array?

    The following code is not valid, but it might help show what I’m going for.

    $images = rwmb_meta( 'savino_gallery', 'type=image&size=large' );
    $thumbs = rwmb_meta( 'savino_gallery', 'type=image&size=thumbnail' );
    
    foreach ($images as $image && $thumbs as $thumb) {
         echo "<li data-thumb='{$thumb['url']}'><img src='{$image['url']}' width='{$image['width']}' height='{$image['height']}' alt='{$image['alt']}' /></li>";
    }

    This may just be a matter of tweaking php syntax, but I’m not sure where to go from here.

    https://www.ads-software.com/plugins/meta-box/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Anh Tran

    (@rilwis)

    I think your code is good, but you can add a small optimization like this:

    $images = rwmb_meta( 'savino_gallery', 'type=image&size=large' );
    
    foreach ($images as $id => $image) {
        list( $thumb ) = wp_get_attachment_image_src( $id, 'thumbnail' );
        echo "<li data-thumb='{$thumb}'><img src='{$image['url']}' width='{$image['width']}' height='{$image['height']}' alt='{$image['alt']}' /></li>";
    }
    Thread Starter dansz

    (@dansz)

    Works perfectly! Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Multiple image sizes within the same foreach loop?’ is closed to new replies.