首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >设置API中的复选框问题

设置API中的复选框问题
EN

WordPress Development用户
提问于 2018-10-09 12:37:32
回答 1查看 154关注 0票数 0

我正在尝试创建一个简单的复选框设置,在主题设置页面中切换博客文章中的某个部分。

不幸的是,它没有保存复选框设置。我选中了这个框,当我刷新页面时,它再次被取消选中。要么是它没有保存设置,要么是checked函数无法工作。我是不是遗漏了什么?

代码语言:javascript
复制
function theme_option_settings(){
    register_setting( 'prev-next-setting', 'prev-next' );
    add_settings_section( 'blog-section', 'Blog Section', 'change_blog_layout_section', 'theme-options' );
    add_settings_field( 'show-prev-next', 'Show Previous/Next Post Section', 'show_prev_next_field', 'theme-options', 'blog-section' );
}

function change_blog_layout_section(){
    echo "Change the blog layout section";
}

function show_prev_next_field(){
    echo get_option( 'prev-next' );
    echo "<input type='checkbox' id='prev-next' name='prev-next' value='1' ".checked(1, get_option('prev-next'), true)."/>";
}
EN

回答 1

WordPress Development用户

发布于 2018-10-10 13:48:34

我设法弄明白了。这是因为在模板页面上,我输出的表单忘记了包含settings_fields函数,所以它没有保存设置。我将下面的代码添加到该页面中,然后它开始工作了:

代码语言:javascript
复制
<?php settings_fields('prev-next-setting'); ?>
票数 0
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/316235

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档