WordPress4定制器的两步使用
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WordPress4定制器的两步使用相关的知识,希望对你有一定的参考价值。
To use WordPress 4 Customizer API I'd need just to do 2 steps: define a data in the array, and call a custom registering function.
<?php if (strtolower (realpath (__FILE__)) == strtolower (realpath ($_SERVER['SCRIPT_FILENAME']))) { header ('Location: http://www.bing.ca/'); die; } // -------------------------------------------------------- // Customize the theme // function HERE_theme_customize ($wp_customize) { // STEP 1: Define the configuration // -------------------------------------------------------- 'title' => __('Header', 'www'), 'description' => __('Configure the Header', 'www'), array ('setting' => 'theme_head_text', 'label' => __('Text in Header', 'www'), 'control' => 'textarea'))), 'title' => __('Footer', 'www'), 'description' => __('Text in the footer', 'www'), 'title' => __('Home Page', 'www'), 'description' => __('Configure the Home Page', 'www'), array ('setting' => 'theme_home_featured_cat', 'label' => __('Featured posts: Category Slug ', 'www')), array ('setting' => 'theme_home_portfolio_title', 'label' => __('Portfolio gallery: Title', 'www')), array ('setting' => 'theme_home_portfolio_id', 'label' => __('Portfolio gallery: ID or Slug', 'www')), array ('setting' => 'theme_home_why_us_image', 'label' => __('Why Us Block: Image', 'www'), 'control' => 'image'), 'title' => __('Social', 'www'), 'description' => __('Links to your Social Sites', 'www'), 'title' => __('Counters', 'www'), 'description' => __('Code for the counters', 'www'), // STEP 2: Call the custom function, see below the source HERE_customizer_register ($wp_customize, $sections); } // -------------------------------------------------------- // Customize the theme // Supports text, textarea and image controls so far function HERE_customizer_register ($wp_customize, $sections) { $priority = 100; { foreach ($sections as $section) { { $wp_customize->add_section ($section['section'], 'description' => $section['description'], } { foreach ($section['settings'] as $setting) { $wp_customize->add_setting ($setting['setting']); switch ($setting['control']) { case 'image': $wp_customize->add_control (new WP_Customize_Image_Control ($wp_customize, $setting['setting'], 'section' => $section['section'], 'settings' => $setting['setting']))); break; case 'textarea': $wp_customize->add_control (new WP_Customize_Control ($wp_customize, $setting['setting'], 'label' => $setting['label'], 'section' => $section['section'], 'settings' => $setting['setting']))); break; default: 'section' => $section['section'])); break; } } } } } }
以上是关于WordPress4定制器的两步使用的主要内容,如果未能解决你的问题,请参考以下文章