first item from array

Support MB Group first item from arrayResolved

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #24224
    Martin RybosMartin Rybos
    Participant

    Please how could i get the first image url from an array.

    foreach ( $disli as $value ) {
        $image = RWMB_Image_Field::file_info( $value, ['size' => 'large'] );
        echo '<a href="' . $image['url'] . '" data-lightbox="'.$dislider['gallname'].'"></a>';
    }
    
    echo '<a href="'.$image['url'][0]. // first item ?? '"
     data-lightbox="'.$dislider['gallname'].'">
    
    <span class="material-icons imag" style="display: block;color:'.$dislider['textcolorr'].'">image</span>
    </a>';
    

    I need to open lightbox with icon but icon needs an url to open it.

    #24231
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Follow your previous topic: https://support.metabox.io/topic/get-advanced-images-from-array/

    /**
     * return an array of image IDs 
    [0] => 234
    [1] => 456
    [2] => 831
    [3] => 1112
     */
    $disli = $dislider['gallimage'];

    To get the first image from the field image_advanced value, please follow this code:

    $image = RWMB_Image_Field::file_info( $disli[0], ['size' => 'large'] );
    echo '<a href="' . $image['url'] . '" data-lightbox="'.$dislider['gallname'].'"></a>';
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.