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(),具体取决于您设置的"类型"。如果未指定类型,则默认为 theme_mod。要检索字段,请使用以下内容:

get_option( 'front_page_options[image_select]', '' );

或者,如果您有多个选项,则可以在数组中检索所有选项,然后根据需要访问它们。

$front_page_options = get_option( 'front_page_options', '' );
$image_select = $front_page_options['image_select'];

这是一个非常简单的示例,但应该让您了解如何访问要查找的值。