问题描述
我在 wordpress 中使用 Carbon Fields。我有一个问题,因为我无法显示媒体库。我在functions.PHP中的代码
function crb_attach_post_Meta_aboutus() {
Container::make( 'post_Meta',__( 'Singlebramy','single' ) )
->where( 'post_type','=','dla-domu' )
->add_fields( array(
Field::make( 'media_gallery','crb_media_gallery','galeria' )
->set_type( 'image' )
));
}
我尝试使用 foreach 但没有用。请帮帮我。
解决方法
好的,我找到了我的问题的答案。我使用了 foreach 和 wp_get_attachment_url(),下面我添加了一个代码片段,其中包含解决难题的方法。
foreach( $media_gallery as $i => $image ){
if($i == 0){
$next = 'active';
}else{
$next = '';
}
echo '<div class="carousel-item '.$next.'">';
echo '<img src="'.wp_get_attachment_url( $image ).'" class="d-block w-100">';
echo '</div>';
}
这是一个带有 bootstrap carousel 的代码片段:)
,要在 Carbon 字段中显示媒体库:
$gallery = carbon_get_post_meta( get_the_ID(),'crb_media_gallery' );
foreach( $gallery as $i => $image ){
echo '<img src="'.wp_get_attach`enter code here`ment_url( $image ).'" class="d-block w-100">';
}