如何解决如何将alt属性放入循环中的img cmb2中?
这是我在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','desc' => esc_html__( 'Cargue las banderas aquí','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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。