duannei0044 2016-02-08 19:01
浏览 36
已采纳

Wordpress Customizer API:访问变量

I have the following code:

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',
  ));
  ...
}

I want to access the front_page_array variables, but all I can find is documentation on simply creating a new .css spreadsheet to make changes. Is there a way I can specifically access the variables like so:

<?php get_header(); ?>

<?php get_customizer_variables('front_page_options'); ?>

<?php get_footer(); ?>
  • 写回答

1条回答 默认 最新

  • dongzhimin2231 2016-02-08 20:03
    关注

    To retrieve values that you have stored, you will either use get_theme_mod() or get_option(), depending on the "type" you set. If no type is given, it defaults to theme_mod. To retrieve a field, use something like:

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

    Alternatively, if you have multiple options, you can retrieve all of them in an array and then access them as needed.

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

    This is a very simple example but should give you an idea of how to access the values you are looking for.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果