我使用下划线来构建主题,并向自定义部分添加了一个图像选择器,它与默认的背景图像部分类似,只是由于某种原因,单击“选择图像”不会打开媒体库。下面是我使用的代码:
function hi_customization_options( $wp_customize ) {
$wp_customize->add_section(
\'landing_page_image\',
array(
\'title\' => \'Landing Page Image\',
\'priority\' => 35,
)
);
$wp_customize->add_setting(
\'lp-image_selector\',
array(
\'default\' => \'\',
)
);
$wp_customize->add_control(
\'lp-image_selector\',
array(
\'label\' => \'Landing Page Image\',
\'section\' => \'landing_page_image\',
\'type\' => \'image\',
)
);
}
add_action( \'customize_register\', \'hi_customization_options\' );
大概我需要向add\\u control部分添加一个“choices”数组,但我不确定如何定位媒体库?
谢谢
SO网友:TJ152
我想出来了。对于任何面临相同问题的人,我最终使用了以下代码:
function hi_customization_options( $wp_customize ) {
$wp_customize->add_section(
\'landing_page_image\',
array(
\'title\' => \'Landing Page Image\',
\'priority\' => 35,
)
);
$wp_customize->add_setting(
\'lp-image_selector\',
array(
\'default\' => \'\',
)
);
$wp_customize->add_setting( \'img-upload\' );
$wp_customize->add_control(
new WP_Customize_Image_Control(
$wp_customize,
\'lp-image_selector\',
array(
\'label\' => \'Landing Page Image\',
\'section\' => \'landing_page_image\',
\'settings\' => \'img-upload\'
)
)
);
}
add_action( \'customize_register\', \'hi_customization_options\' );