Wordpress Customizer API:访问变量
Wordpress Customizer API: access variables
我有以下代码:
function color_scheme_customizer_register($wp_customize) {
$wp_customize->add_section('front_page', array(
'title' => __('Front Page'),
'priority' => 120,
));
// MAIN IMAGE
$wp_customize->add_setting('front_page_options[image_select]', array(
'capability' => 'edit_theme_options',
'type' => 'option',
));
$wp_customize->add_control( new WP_Customize_Image_Control($wp_customize, 'image_select', array(
'label' => __('Main Image', 'themename'),
'section' => 'front_page',
'settings' => 'front_page_options[image_select]',
)));
// FEATURE ONE
$wp_customize->add_setting('front_page_options[feature_one_page]', array(
'capability' => 'edit_theme_options',
'type' => 'option',
));
$wp_customize->add_control('feature_one_page', array(
'label' => __('Featured Page One'),
'section' => 'front_page',
'settings' => 'front_page_options[feature_one_page]',
'type' => 'dropdown-pages',
));
$wp_customize->add_setting('front_page_options[feature_one_textarea]', array(
'capability' => 'edit_theme_options',
'type' => 'option',
));
$wp_customize->add_control('feature_one_textarea', array(
'label' => __('Featured Page One Summary'),
'section' => 'front_page',
'settings' => 'front_page_options[feature_one_textarea]',
'type' => 'textarea',
));
...
}
我想访问 front_page_array 变量,但我所能找到的只是关于简单地创建一个新的 .css 电子表格以进行更改的文档。有没有一种方法可以像这样专门访问变量:
<?php get_header(); ?>
<?php get_customizer_variables('front_page_options'); ?>
<?php get_footer(); ?>
要检索您存储的值,您将使用 get_theme_mod() 或 get_option(),具体取决于您设置的 "type"。如果没有给出类型,它默认为 theme_mod。要检索字段,请使用类似:
get_option( 'front_page_options[image_select]', '' );
或者,如果您有多个选项,您可以在数组中检索所有选项,然后根据需要访问它们。
$front_page_options = get_option( 'front_page_options', '' );
$image_select = $front_page_options['image_select'];
这是一个非常简单的示例,但应该能让您了解如何访问您要查找的值。
我有以下代码:
function color_scheme_customizer_register($wp_customize) {
$wp_customize->add_section('front_page', array(
'title' => __('Front Page'),
'priority' => 120,
));
// MAIN IMAGE
$wp_customize->add_setting('front_page_options[image_select]', array(
'capability' => 'edit_theme_options',
'type' => 'option',
));
$wp_customize->add_control( new WP_Customize_Image_Control($wp_customize, 'image_select', array(
'label' => __('Main Image', 'themename'),
'section' => 'front_page',
'settings' => 'front_page_options[image_select]',
)));
// FEATURE ONE
$wp_customize->add_setting('front_page_options[feature_one_page]', array(
'capability' => 'edit_theme_options',
'type' => 'option',
));
$wp_customize->add_control('feature_one_page', array(
'label' => __('Featured Page One'),
'section' => 'front_page',
'settings' => 'front_page_options[feature_one_page]',
'type' => 'dropdown-pages',
));
$wp_customize->add_setting('front_page_options[feature_one_textarea]', array(
'capability' => 'edit_theme_options',
'type' => 'option',
));
$wp_customize->add_control('feature_one_textarea', array(
'label' => __('Featured Page One Summary'),
'section' => 'front_page',
'settings' => 'front_page_options[feature_one_textarea]',
'type' => 'textarea',
));
...
}
我想访问 front_page_array 变量,但我所能找到的只是关于简单地创建一个新的 .css 电子表格以进行更改的文档。有没有一种方法可以像这样专门访问变量:
<?php get_header(); ?>
<?php get_customizer_variables('front_page_options'); ?>
<?php get_footer(); ?>
要检索您存储的值,您将使用 get_theme_mod() 或 get_option(),具体取决于您设置的 "type"。如果没有给出类型,它默认为 theme_mod。要检索字段,请使用类似:
get_option( 'front_page_options[image_select]', '' );
或者,如果您有多个选项,您可以在数组中检索所有选项,然后根据需要访问它们。
$front_page_options = get_option( 'front_page_options', '' );
$image_select = $front_page_options['image_select'];
这是一个非常简单的示例,但应该能让您了解如何访问您要查找的值。