在为图片上传创建 CMB2 file_list 以填充图库时,CMB2 在线示例无法显示诸如 img alt 标签之类的选项并向图片添加类。我不知道如何访问图像,但只能通过下面提供的代码。例如,我需要向图库中的第一张图片添加一个类并添加 alt 标签?如果有人可以提供帮助,我将不胜感激!
function cmb2_output_file_list( $file_list_meta_key, $img_size = '' ) {
// Get the list of files
$files = get_post_meta( get_the_ID(), $file_list_meta_key, 1 );
// Loop through them and output an image
foreach ( (array) $files as $attachment_id => $attachment_url ) {
echo '<div class="slide">';
echo wp_get_attachment_image( $attachment_id, $img_size);
echo '</div>';
}
}
cmb2_output_file_list( 'bs_bautage_pic', '');