【发布时间】:2012-01-14 22:51:19
【问题描述】:
在 Wordpress 中,我尝试从头开始创建元框脚本,以更好地理解 Wordpress 和 PHP。
我在多维数组上的 for each 循环中遇到了一些问题。我正在使用 PHP5。
这是数组:
$meta_box = array();
$meta_box[] = array(
'id' => 'monitor-specs',
'title' => 'Monitor Specifications',
'context' => 'normal',
'priority' => 'default',
'pages' => array('monitors', 'products'),
'fields' => array(
array(
'name' => 'Brand',
'desc' => 'Enter the brand of the monitor.',
'id' => $prefix . 'monitor_brand',
'type' => 'text',
'std' => ''
)
)
);
这是 for each 循环:
foreach ($meta_box['pages'] as $post_type => $value) {
add_meta_box($value['id'], $value['title'], 'je_format_metabox', $post_type, $value['context'], $value['priority']);
}
我要做的是循环遍历“pages”数组中的键,该数组是“meta_box”数组中的一个数组,同时能够使用“meta_box”数组的键值。
我需要为每个循环嵌套一些吗?
非常感谢一些正确方向的指点,以便我可以解决这个问题。
【问题讨论】:
-
您想对页面中的这些项目做什么?
-
如果 $meta_box 已经描述了数组,你会得到 $post_type 0,1 和空的 $value['context'], $value['priority']。但你的方式应该是空数组,因为 $meta_box['pages'] 是空的
-
to better understand both Wordpress and PHP.[rant]Wordpress 并不是最好的学习代码[/rant]
标签: php arrays wordpress foreach meta-boxes