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

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 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据