我用这个html标记对一些数据进行排序
<div class="row">
<div class="col-xs-2">
<img src="images/member-schools/ms1.jpg" class="img-responsive">
</div>
<div class="col-xs-4">
<h4>American International School - East</h4>
</div>
<div class="col-xs-2">
<img src="images/member-schools/ms2.jpg" class="img-responsive">
</div>
<div class="col-xs-4">
<h4>Dover American International School</h4>
</div>
我从我使用的可重复组元数据库中提取数据CMB2
这是注册的metabox的代码
function schools() {
// Start with an underscore to hide fields from custom fields list
$prefix = \'schools_\';
/**
* Repeatable Field Groups
*/
$schools= new_cmb2_box( array(
\'id\' => $prefix . \'metabox\',
\'title\' => __( \'schools\', \'cmb2\' ),
\'object_types\' => array( \'page\', ),
\'show_on\' => array( \'key\' => \'id\', \'value\' => 6 ),
\'closed\' => true,
) );
$group_field_id = $schools->add_field( array(
\'id\' => $prefix . \'field\',
\'type\' => \'group\',
\'options\' => array(
\'group_title\' => __( \'Slide {#}\', \'cmb2\' ), // {#} gets replaced by row number
\'add_button\' => __( \'Add Another Slide\', \'cmb2\' ),
\'remove_button\' => __( \'Remove Slide\', \'cmb2\' ),
\'sortable\' => true, // beta
),
) );
$schools->add_group_field( $group_field_id, array(
\'name\' => __( \'Photo\', \'cmb2\' ),
\'id\' => \'photo\',
\'type\' => \'file\',
) );
$schools->add_group_field( $group_field_id, array(
\'name\' => __( \'Name\', \'cmb2\' ),
\'id\' => \'name\',
\'type\' => \'text\',
) );}
我通过这个代码提取数据
$schools = get_post_meta( get_the_ID(), \'schools_field\', true );
其中$schools是一个数组,其中包含每个条目的图像和标题,我可以通过循环提取值。我的问题是如何添加
<div class="row">
该数组中的每两个项,因为我需要为每两个条目对应一行
编辑:var\\u转储结果
array(3) {
[0] => array(3) {
["photo_id"] => string(2) "89"
["photo"] => string(56) "http://localhost/NCSR/wp-content/uploads/2015/06/ms3.jpg"
["name"] => string(8) "School 1"
}
[1] => array(3) {
["photo_id"] => string(2) "88"
["photo"] => string(56) "http://localhost/NCSR/wp-content/uploads/2015/06/ms2.jpg"
["name"] => string(8) "school 2"
}
[2] => array(3) {
["photo_id"] => string(2) "87"
["photo"] => string(56) "http://localhost/NCSR/wp-content/uploads/2015/06/ms1.jpg"
["name"] => string(8) "school 3"
}
}