How to refer to cloneable single_image field?

Support General How to refer to cloneable single_image field?

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #14220
    EddyPiVEddyPiV
    Participant

    Hi,

    How do I display the cloneable single image fields in the frontend?
    This is the code of the custom field:

    array (
                    'id' => 'fotos',
                    'type' => 'single_image',
                    'name' => 'Foto\'s',
                    'force_delete' => 1,
                    'clone' => 1,
                    'max_clone' => 3,
                    'add_button' => 'Nog een foto',
                ),

    How to refer to the individual fields?
    [rwmb_meta meta_key="fotos???" link="true" size="thumbnail"]

    #14221
    EddyPiVEddyPiV
    Participant

    To add here: I guess it would be better to display the images as a gallery, so that the images are all nicely displayed, also if e.g. the 2nd image would be deleted.

    How to disply the images as a gallery?

    #14231
    Anh TranAnh Tran
    Keymaster

    Hi,

    Yes, you can display images as a gallery. Please try this code:

    $images = rwmb_meta( 'fotos', ['size' => 'thumbnail'] );
    echo '<div class="gallery">';
    foreach ( $images as $image ) {
        echo "<a href='{$image['full_url']}'><img src='{$image['url'}'></a>";
    }
    echo '</div>';
    #14250
    EddyPiVEddyPiV
    Participant

    Anh,

    When I add this code to XYZ PHP Code Snippet, the webpage stops loading.
    What am I doing wrong?

    #14273
    Anh TranAnh Tran
    Keymaster

    Which PHP version are you using? I'm writing in PHP 5.4 (that accepts short array syntax). Please upgrade if you're using lower PHP version.

    #14299
    EddyPiVEddyPiV
    Participant

    I'm running PHP 7.2.

    #14315
    Anh TranAnh Tran
    Keymaster

    Can you turn on debug and see what the error is? My code is created in my mind without testing, so it might have some conflict.

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