Support » Plugin: Meta Box » Is it possible to display single image?

  • Resolved yurenlimbu

    (@yurenlimbu)


    Is it possible to display single images?

    $images = rwmb_meta( 'gallery', 'size=YOURSIZE' ); // Since 4.8.0
    $images = rwmb_meta( 'gallery', 'type=image&size=YOURSIZE' ); // Prior to 4.8.0
    
    if ( !empty( $images ) ) {
        foreach ( $images as $image ) {
    //IMAGE 1
            echo '<a href="', esc_url( $image['full_url'] ), '" title="', esc_attr( $image['title'] ), '" rel="lightbox"><img style="padding:5px" src="', esc_url( $image['url'] ), '"  alt="', esc_attr( $image['alt'] ), '"></a>';
    
    //IMAGE 2
    echo '<a href="', esc_url( $image['full_url'] ), '" title="', esc_attr( $image['title'] ), '" rel="lightbox"><img style="padding:5px" src="', esc_url( $image['url'] ), '"  alt="', esc_attr( $image['alt'] ), '"></a>';
    
    //IMAGE 3
    echo '<a href="', esc_url( $image['full_url'] ), '" title="', esc_attr( $image['title'] ), '" rel="lightbox"><img style="padding:5px" src="', esc_url( $image['url'] ), '"  alt="', esc_attr( $image['alt'] ), '"></a>';
        }
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Anh Tran

    (@rilwis)

    Hi @yurenlimbu,

    If you want to display only 1st image of the gallery, then you can use this code:

    $images = rwmb_meta( 'gallery', 'size=YOURSIZE' );
    
    if ( !empty( $images ) ) {
        $image = reset( $images );
        echo '<a href="', esc_url( $image['full_url'] ), '" title="', esc_attr( $image['title'] ), '" rel="lightbox"><img style="padding:5px" src="', esc_url( $image['url'] ), '"  alt="', esc_attr( $image['alt'] ), '"></a>';
    }
    yurenlimbu

    (@yurenlimbu)

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.