Custom Fields
Re-Envisioned
Support General How to refer to cloneable single_image field?

This topic contains 6 replies, has 2 voices, and was last updated by  Anh Tran 3 weeks, 3 days ago.

  • Creator
    Topic
  • #14220

    LFFprop
    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"]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Author
    Replies
  • #14221

    LFFprop
    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 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

    LFFprop
    Participant

    Anh,

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

    #14273

    Anh 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

    LFFprop
    Participant

    I’m running PHP 7.2.

    #14315

    Anh 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 6 replies - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.