我正在使用 WP Alchemy 创建一个带有多个复选框的元框。
我遇到的麻烦是,我有一个学术课程的 csv 列表,我想从中创建复选框选项。所以我把 csv 变成了一个数组,盒子是由这个数组组成的。但是,使用我现在拥有的代码,仅在数组中创建了最后一行。
<?php
$file_handle = fopen('curriculum.csv', 'r');
while (!feof($file_handle) ) {
$line_of_text = fgets($file_handle);
$parts = explode(',', $line_of_text);
$items = array ($parts[2] .$parts[3], );
}
fclose($file_handle);
?>
<?php foreach ($items as $i => $item): ?>
<?php $mb->the_field('cb_ex3'); ?>
<!-- similar to test #2, the same thing can be accomplished by simply
adding array brackets "[]" to the name -->
<input type="checkbox" name="<?php $mb->the_name(); ?>[]" value="<?php echo $item; ?>"<?php $mb->the_checkbox_state($item); ?>/> <?php echo $item; ?><br/>
<?php endforeach; ?>
所以在几百行代码中,我得到的只是最后一行。这是我正在使用的实际文件:http ://www.ouhsd.k12.ca.us/educational_services/curriculum/curriculum.csv