Custom Fields
Re-Envisioned
Support Meta Box Group first item from array

  • Creator
    Topic
  • #24224
    Resolved Martin 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.

Viewing 1 replies (of 1 total)
  • Author
    Replies
  • #24231
    Long Nguyen
    Moderator

    Hi,

    Follow your previous topic: https://metabox.io/support/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 1 replies (of 1 total)
  • You must be logged in to reply to this topic.