问题描述
这是我在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 (将#修改为@)