Php 如何将img cmb2中的alt属性放入循环中?
这是我在stackoverflow中的第一个问题。我尝试了很多方法来放置alt属性,但都做不到。这是我的海关代码字段(CMB2) 这是我的循环代码Php 如何将img cmb2中的alt属性放入循环中?,php,wordpress,wordpress-theming,cmb2,Php,Wordpress,Wordpress Theming,Cmb2,这是我在stackoverflow中的第一个问题。我尝试了很多方法来放置alt属性,但都做不到。这是我的海关代码字段(CMB2) 这是我的循环代码 <div id="contenedorPaises" class="owl-carousel owl-theme owl-loaded owl-drag"> <?php $banderas = get_post_meta(get_the_ID(), 'edc_home_pa
<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>
“class=”img流体“alt=”“>
这是源页面
<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>
这是源页面(见图)
向我们显示页面源代码,这样我们就可以看到页面的特定部分输出了什么。我刚刚更新了帖子,谢谢!查找
浏览器和页面源代码右键单击->查看页面源代码我再次更新了帖子。谢谢$image\u alt
必须为空,这可能意味着获取位置t_meta($bandera,“_wp_attachment_image_alt”,true);
错误或也未返回任何内容
<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>