从WordPress主题中的Kirki定制器字段获取值

我正在使用Kirki插件在WordPress定制器中添加字段和部分。到目前为止, 我可以将一个字段添加到定制器中, 但是我对如何将数据返回到主题感到困惑。我有点累, 所以我可能会缺少一些东西。这是我到目前为止所拥有的:

Kirki::add_config('theme_config_id', array(
  'capability'    => 'edit_theme_options', 'option_type'   => 'theme_mod', ));

Kirki::add_section('footer_section', array(
  'title'          => __('Footer'), 'description'    => __('Add custom footer here'), 'panel'          => '', // Not typically needed.
  'priority'       => 160, 'capability'     => 'edit_theme_options', 'theme_supports' => '', // Rarely needed.
));


Kirki::add_field('theme_config_id', [
  'type'        => 'editor', 'settings'    => 'my_setting', 'label'       => esc_html__('Footer Content', 'kirki'), 'description' => esc_html__('This content will show in the footer.', 'kirki'), 'section'     => 'footer_section', 'default'     => '', ]);

我正在阅读使用以下方法尝试从此处得出值:

$value = Kirki::get_option( $config_id, $option_id );

但是我不确定$ config_id或$ option_id在哪里(或什么位置)?我有一种缺失的感觉, 我已经阅读了文档, 但感觉不到。


#1


这是正确的代码

$value = Kirki::get_option( 'config_id', 'option_id' );

所以就你而言

$value = Kirki::get_option( 'theme_custom', 'footer_content' );

#2


在浏览了一下互联网之后, 我能够阅读更多的文档以及其他示例, 并且能够弄清自己做错了什么。总的来说, 我很接近, 但最终还是清理干净, 只在模板文件中使用了WordPress get_theme_mod()(在本例中为footer.php文件)。

我最终得到的是:

Kirki::add_config('theme_custom', array(
  'capability'    => 'edit_theme_options', 'option_type'   => 'theme_mod'
));

Kirki::add_section('footer_section', array(
  'title'          => __('Footer'), 'description'    => __('Add custom footer here'), 'panel'          => '', // Not typically needed.
  'priority'       => 160, 'capability'     => 'edit_theme_options', 'theme_supports' => '', // Rarely needed.
));


Kirki::add_field('theme_custom', array(
  'type'        => 'editor', 'settings'    => 'footer_content', 'label'       => esc_html__('Footer Content', 'kirki'), 'description' => esc_html__('This content will show in the footer.', 'kirki'), 'section'     => 'footer_section', 'default'     => '', 'priority'    => 10
));

在我的footer.php文件中, 添加了以下内容:

<?php $value = get_theme_mod('footer_content', ''); ?>
<?php echo($value); ?>

当然, 这是实现此目标的超级基本方法。在发布之前, 我将尝试找出如何使其刷新定制程序预览的方法。但目前看来, 这似乎行之有效。

来源:

https://www.srcmini02.com/62597.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_42221.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?