
7折
减价出售
¥799
Kirki是WordPress主题定制器(Customizer)的强大扩展框架,它简化了复杂控件创建过程,为开发者提供了更丰富的配置选项和更优雅的实现方式。
Kirki通过面向对象的API取代了WordPress原生的定制器函数,使代码更简洁:
// 原生WordPress方式
$wp_customize->add_setting('primary_color', array('default' => '#3498db'));
$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'primary_color', array(
'label' => '主色调'
)));
// Kirki方式
Kirki::add_field('theme_config_id', array(
'type' => 'color',
'settings' => 'primary_color',
'label' => esc_html__('主色调', 'textdomain'),
'default' => '#3498db'
));
Kirki内置了30+种专业控件,远超原生定制器:
Kirki可自动将设置值转换为CSS并注入页面:
Kirki::add_field('theme_config_id', array(
'type' => 'typography',
'settings' => 'body_typography',
'label' => esc_html__('正文排版', 'textdomain'),
'section' => 'typography',
'default' => array(
'font-family' => 'Roboto',
'font-size' => '16px',
),
'output' => array( // 自动生成CSS
array(
'element' => array('body', '.entry-content'),
),
),
));
Kirki::add_section('typography', array(
'title' => esc_html__('排版设置', 'textdomain'),
'priority' => 30,
));
Kirki::add_field('theme_config_id', array(
'type' => 'typography',
'settings' => 'heading_typography',
'label' => esc_html__('标题字体', 'textdomain'),
'section' => 'typography',
'default' => array(
'font-family' => 'Poppins',
'variant' => '700',
),
'output' => array(
array(
'element' => array('h1', 'h2', 'h3'),
),
),
));
2. 实现响应式布局控制
Kirki::add_field('theme_config_id', array(
'type' => 'dimensions',
'settings' => 'content_padding',
'label' => esc_html__('内容区域边距', 'textdomain'),
'description' => esc_html__('设置内容区域四周边距', 'textdomain'),
'section' => 'layout',
'default' => array(
'top' => '2em',
'right' => '3em',
'bottom' => '2em',
'left' => '3em',
),
'output' => array(
array(
'element' => '.content-area',
),
),
));
3. 构建高级颜色系统
Kirki::add_field('theme_config_id', array(
'type' => 'multicolor',
'settings' => 'button_colors',
'label' => esc_html__('按钮颜色', 'textdomain'),
'section' => 'colors',
'choices' => array(
'text' => esc_html__('文字颜色', 'textdomain'),
'background' => esc_html__('背景颜色', 'textdomain'),
'hover' => esc_html__('悬停颜色', 'textdomain'),
),
'default' => array(
'text' => '#ffffff',
'background' => '#3498db',
'hover' => '#2980b9',
),
));
// 初始化配置
Kirki::add_config('theme_config_id', array(
'capability' => 'edit_theme_options',
'option_type' => 'theme_mod', // 或'option'
));
// 所有字段需关联到配置ID
Kirki::add_field('theme_config_id', array(
// 字段参数
));
Kirki::add_field('theme_config_id', array(
'type' => 'switch',
'settings' => 'show_header',
'label' => esc_html__('显示页眉', 'textdomain'),
'section' => 'header',
'default' => true,
));
Kirki::add_field('theme_config_id', array(
'type' => 'color',
'settings' => 'header_bg',
'label' => esc_html__('页眉背景色', 'textdomain'),
'section' => 'header',
'active_callback' => array( // 条件显示
array(
'setting' => 'show_header',
'operator' => '==',
'value' => true,
),
),
));
特性 | 原生定制器 | Kirki框架 |
---|---|---|
控件类型 | 基础控件(10+) | 高级控件(30+) |
代码复杂度 | 冗长 | 简洁 |
CSS输出 | 需手动处理 | 自动生成 |
条件逻辑 | 有限支持 | 强大支持 |
排版控制 | 不支持 | 完整支持 |
学习曲线 | 平缓 | 中等 |
composer require kirki-framework/kirki
// 步骤1:初始化配置
Kirki::add_config('theme_config');
// 步骤2:添加面板/部分
Kirki::add_panel('theme_options', array(
'title' => '主题选项',
'priority' => 160,
));
// 步骤3:添加字段
Kirki::add_field('theme_config', array(
'type' => 'color',
'settings' => 'primary_color',
'label' => '主色调',
'section' => 'colors',
'default' => '#3498db',
));
Kirki框架已经成为现代WordPress主题开发的标准配置之一,被包括Astra、OceanWP在内的众多流行主题采用。它既保留了WordPress定制器的易用性,又提供了专业级主题选项所需的强大功能,是平衡开发效率与用户体验的理想选择。
减价出售
减价出售
减价出售
减价出售
电话咨询
1855-626-3292
微信咨询