【问题标题】:Having multiple values in Wordpress theme customization dashboard在 Wordpress 主题自定义仪表板中具有多个值
【发布时间】:2015-11-21 03:41:13
【问题描述】:

在我的主题自定义菜单中,我希望有一个页脚选项部分。这是列数以及每列的标题标题。到目前为止,我所拥有的是图像,所有选项都保存为相同的东西。如何更改它,使每个部分都有不同的值?

我在functions.php中的代码:

/*
Footer headers and number of columns
*/
$wp_customize->add_setting( 'footer_options', array(
  'title' => __( 'Footer column options', 'Universal Theme'),
  'capability' => 'edit_theme_options',
  'description' => __( 'Update footer options')
));

$wp_customize->add_section( 'footer_options', array(
  'title' => __( 'Footer options', 'Universal Theme' ),
  'capability' => 'edit_theme_options'
));

$wp_customize->add_control( 'footer_options', array(
  'settings' => 'footer_options',
  'section' => 'footer_options',
  'type' => 'radio',
  'choices' => array(
    1 => __( '1' ),
    2 => __( '2' ),
    3 => __( '3' ),
    4 => __( '4' ),
    5 => __( '5' ),
    6 => __( '6' )
  ),
  'label' => __( 'Number of columns' )
));

$wp_customize->add_control( 'footer_options_header1', array(
  'settings' => 'footer_options',
  'section' => 'footer_options',
  'type' => 'text',
  'label' => __( 'Footer header 1' )
));

$wp_customize->add_control( 'footer_options_header2', array(
  'settings' => 'footer_options',
  'section' => 'footer_options',
  'type' => 'text',
  'label' => __( 'Footer header 2' )
));

$wp_customize->add_control( 'footer_options_header3', array(
  'settings' => 'footer_options',
  'section' => 'footer_options',
  'type' => 'text',
  'label' => __( 'Footer header 3' )
));

$wp_customize->add_control( 'footer_options_header4', array(
  'settings' => 'footer_options',
  'section' => 'footer_options',
  'type' => 'text',
  'label' => __( 'Footer header 4' )
));

$wp_customize->add_control( 'footer_options_header5', array(
  'settings' => 'footer_options',
  'section' => 'footer_options',
  'type' => 'text',
  'label' => __( 'Footer header 5' )
));

$wp_customize->add_control( 'footer_options_header6', array(
  'settings' => 'footer_options',
  'section' => 'footer_options',
  'type' => 'text',
  'label' => __( 'Footer header 6' )
));

所有这些都在一个放在'customize_register'的add_action中的函数中

我需要进行哪些更改才能使其正常工作?

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    我们可以使用相同的部分,但我们需要为每个控件添加设置。现在您对所有控件都使用相同的设置 ID。所以每个值都会存储在 footer_options 中。

    像这样使用:

    $wp_customize->add_setting( 'footer_options_one', array(
      'title' => __( 'Footer column options', 'Universal Theme'),
      'capability' => 'edit_theme_options',
          'description' => __( 'Update footer options')
    ));
    
    
    $wp_customize->add_setting( 'footer_options_two', array(
      'title' => __( 'Footer column options', 'Universal Theme'),
      'capability' => 'edit_theme_options',
          'description' => __( 'Update footer options')
    ));
    

    要了解它,您可以访问: https://codex.wordpress.org/Plugin_API/Action_Reference/customize_register

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-01-12
      • 1970-01-01
      • 1970-01-01
      • 2011-07-29
      • 1970-01-01
      • 2012-01-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多