如何显示存储在元框图像字段中的多个图像

时间:2017-07-15 10:09:39

标签: wordpress image meta-boxes

我想显示来自元框图像的多个图像。结果显示“数组”。我想要显示“阵列”的图像。

function.php文件中的元框图像代码:

add_filter( 'rwmb_meta_boxes', 'YOURPREFIX_register_meta_boxes' );
 function YOURPREFIX_register_meta_boxes( $meta_boxes ) {
     $prefix = 'rw_';

      $meta_boxes[] = array(
         'id'         => 'personal3',
         'title'      => __( 'Image', 'textdomain' ),
         'post_types' => array( 'post', 'page' ),
         'fields'     => array(
             array(
                 'name' => __( 'Photo', 'textdomain' ),
                 'id'   => $prefix . 'Photo',
                 'type' => 'image',
                 'force_delete'     => false,
                 // Maximum image uploads
                 'max_file_uploads' => 4,
                // Display the "Uploaded 1/2 files" status
                 'max_status'       => true,
             ),
         )
     );
     return $meta_boxes; }

在loop.php文件中显示代码:

<?php 
      echo $myvar = rwmb_meta( 'rw_Photo');
?>

1 个答案:

答案 0 :(得分:3)

图像数组

在循环中添加foreach循环

 <?php
    $myvar_array = rwmb_meta( 'rw_Photo');
    foreach ( $myvar_array as $myvar_value )
    {
         //$myvar_value['url'] 
        ?>
        <img src="<?php echo $myvar_value['url']; ?>" />
        <?php
    }
    ?>