我对wordpress很陌生,我在其他人的代码中深陷其中:(。因此,我在wp\\U选项表中将此数据数组作为option\\u值
a:2:{s:16:"block1_names_arr"; a:7:{i:0; s:6:"name1"; i:1; s:9:"name2"; i:2; s:8:"name3"; i:3; s:12:"name4"; i:4; s:11:"name5"; i:5; s:7:"name6"; i:6; s:7:"name7"; }s:16:"block2_names_arr"; a:7:{i:0; s:44:"surname1"; i:1; s:76:"surname2"; i:2; s:62:"surname3"; i:3; s:86:"surname4"; i:4; s:67:"surname5"; i:5; s:68:"surname6"; i:6; s:48:"surname7"; }}
我想在前端创建一个两列的表,每行显示姓名。我创建了一个函数,并设法显示第一组数据(名称),但找不到显示第二组数据的方法
function names_table(){
$options = get_option(\'all_names\');
$block1_names_arr = $options[\'block1_names_arr\'];
$block2_names_arr = $options[\'block2_names_arr\'];
$html = \'
<table class="table_open uv-table-dailies responsive table">
<thead>
<tr>
<th>Event</th>
<th>Pick</th>
</tr>
</thead>
<tbody>\';
foreach($block1_names_arr as $bookie){
$html.=\'<tr class="tr_open_res">
<td>\'. $bookie .\'</td>
<td>CANT DISPLAY THE SURNAMES HERE</td>
</tr>\';
}
$html.=\'
</tbody>
</table>\';
return $html;}
我甚至不确定这样做是否正确。。。
最合适的回答,由SO网友:Mayeenul Islam 整理而成
不知道您是如何存储数据的。只是根据假设回答:
<?php
$options = get_option(\'all_names\');
?>
<table>
<tbody>
<?php
$_counter = 0;
foreach( $options as $option ) : ?>
<tr>
<td><?php echo $option[\'block1_names_arr\'][$_counter]; ?></td>
<td><?php echo $option[\'block2_names_arr\'][$_counter]; ?></td>
</tr>
<?php
$_counter++;
endforeach; ?>
</tbody>
</table>