0

这是我在stackoverflow中的第一个问题。我尝试了很多放置 alt 属性的方法,但我做不到。这是我的海关代码(CMB2)

add_action( 'cmb2_admin_init', 'edc_campos_homepage' );
function edc_campos_homepage() {
    $prefix = 'edc_home_page_';
    $id_home = get_option('page_on_front');
    $edc_campos_homepage = new_cmb2_box( array(
        'id'           => $prefix . 'homepage',
        'title'        => esc_html__( 'Campos de la pagina de Inicio', 'cmb2' ),
        'object_types' => array( 'page' ), // Post type
        'context'      => 'normal',
        'priority'     => 'high',
        'show_names'   => true, // Show field names on the left
        'show_on'      => array(
            'id' => array( $id_home ),
        ), // Specific post IDs to display this metabox
    ) );
    $edc_campos_homepage->add_field( array(
        'name'         => esc_html__( 'Países participantes', 'cmb2' ),
        'desc'         => esc_html__( 'Cargue las banderas aquí', 'cmb2' ),
        'id'           => $prefix . 'banderas',
        'type'         => 'file_list',
        'preview_size' => array( 100, 100 ), // Default: array( 50, 50 )
    ) );
}

这是我的循环代码

 <div id="contenedorPaises" class="owl-carousel owl-theme owl-loaded owl-drag">
    <?php 
    $banderas = get_post_meta(get_the_ID(), 'edc_home_page_banderas',true );
    foreach($banderas as $id=> $bandera){ ?>
      <div class="item">
        <div class="product-wrapper">
          <?php 
            $bandera = wp_get_attachment_image_url($id, 'full');
            $image_alt = get_post_meta($bandera, '_wp_attachment_image_alt', true);
           ?>
            <img src="<?php echo $bandera ?>" class="img-fluid" alt="<?php echo $image_alt ?>">
        </div>
      </div>
    <?php }?>
  </div>

这是源页面

<div class="owl-item" style="width: 316.6px;">
  <div class="item">
   <div class="product-wrapper">
    <img src="http://domainName/wp-content/uploads/2020/09/el-salvador.png" class="img-fluid" alt="">
      </div>
    </div>
  </div>

这是源页面(见图)

图片说明

4

0 回答 0