CMB2可重复的file_list类型

时间:2019-07-11 14:58:47

标签: php wordpress cmb2

我到处搜索有关如何填充/访问在CMB2中的可重复文件列表组内输入的图像的示例。我能找到的所有示例仅适用于单个图像:这是链接https://github.com/CMB2/CMB2/wiki/Field-Types#group

MY CODE:

// creating a group

$group_field_id = $bautage->add_field( array(
id'          => 'tagen_entries',
'type'        => 'group',
'description' => __( 'Tagen', 'cmb2' ),
'repeatable'  => true,
'options'     => array(
'group_title'       => __( 'Tagen {#}', 'cmb2' ), // since version 1.1.4, {#} gets replaced by row number
'add_button'        => __( 'Add Another Entry', 'cmb2' ),
'remove_button'     => __( 'Remove Entry', 'cmb2' ),
'sortable'          => true,
 ),
 ) );

 // creating repeatable fields

$bautage->add_group_field( $group_field_id, array(
'name' => 'Tag Name',
'id'   => 'tag_name',
'type' => 'text',
) );

$bautage->add_group_field( $group_field_id, array(
'name' => 'Tage Photos',
'id'   => 'tage_photos',
'type' => 'file_list',
) );

 // page code

$tagen_entries = get_post_meta( get_the_ID(), 'tagen_entries', true );                  

 foreach ( (array) $tagen_entries as $key => $entry ) {

 if ( isset( $entry['tag_name'] ) ) {
   $tag_name = esc_html( $entry['tag_name'] );
   echo $tag_name;
 }

 if ( isset( $entry['tage_bildern'] ) ) {

 // loop to bring all the photos
// also need the first photo from each entry to be used as a click trigger to open the slideshow

 }

}

0 个答案:

没有答案