我正在尝试向每个页面添加一个元框,该页面是所有已注册边栏的下拉列表,然后保存在自定义字段中。
我在用这个metabox class
我已经做到了这一点:
// get registered Sidebars
$sidebars = $GLOBALS[\'wp_registered_sidebars\'];
foreach ( $sidebars as $sidebar ) {
$sidebar_options[$sidebar[\'name\']] = $sidebar[\'name\'];
}
然后我在metabox声明中调用$sidebars变量,如下所示:
$meta_boxes[] = array(
\'id\' => \'page_metabox\',
\'title\' => \'Page Custom Fields\',
\'pages\' => array( \'page\', ), // Post type
\'context\' => \'normal\',
\'priority\' => \'high\',
\'show_names\' => true, // Show field names on the left
\'fields\' => array(
array(
\'name\' => \'Page Sidebar\',
\'desc\' => \'Choose the Sidebar to show on this page.\',
\'id\' => /*$prefix .*/ \'erh_page_sidebar\',
\'type\' => \'select\',
\'options\' => $sidebar_options,
)
)
);
这是$sidebar\\u选项的结果:
$sidebar_options = array (
\'Header Sidebar\' => \'Header Sidebar\',
\'Main Sidebar\' => \'Main Sidebar\',
\'News Sidebar\' => \'News Sidebar\',
\'Home Panel 1\' => \'Home Panel 1\',
\'Home Panel 2\' => \'Home Panel 2\',
\'Home Panel 3\' => \'Home Panel 3\',
\'Footer 1 Sidebar\' => \'Footer 1 Sidebar\',
\'Footer 2 Sidebar\' => \'Footer 2 Sidebar\',
\'Footer 3 Sidebar\' => \'Footer 3 Sidebar\',
\'Footer 4 Sidebar\' => \'Footer 4 Sidebar\',
\'Footer 5 Sidebar\' => \'Footer 5 Sidebar\',
\'Footer 6 Sidebar\' => \'Footer 6 Sidebar\',
\'Right Sidebar 1\' => \'Right Sidebar 1\',
\'Staff login Sidebar\' => \'Staff login Sidebar\',
\'Staff Sidebar\' => \'Staff Sidebar\',
\'Careers Sidebar\' => \'Careers Sidebar\',
\'Care Providers Sidebar\' => \'Care Providers Sidebar\',
)
我的问题是,这个metabox类希望下拉选项采用这种形式,我不知道如何做到这一点:
array( \'name\' => \'Sidebar 1\', \'value\' => \'Right Sidebar 1\', ),
array( \'name\' => \'Sidebar 2\', \'value\' => \'Right Sidebar 2\', ),
array( \'name\' => \'Sidebar 3\', \'value\' => \'Right Sidebar 3\', ),
非常感谢您的帮助:-)