您好,我正在通过阅读WPTUT上的WordPress设置Api的完整指南来学习向WordPress主题添加主题选项。我已经读到了第四部分,并停下来为自己创建了一个示例,因为我对如何在页面中添加我创建的部分感到困惑。这是我的代码:
function thanatos_theme_menu(){
add_theme_page(
"Thanathos Theme Options",
"Thanathos Theme",
"administrator",
"thanathos_theme_options",
"thanathos_theme_display_callback"
);
}
add_action(\'admin_menu\' , \'thanatos_theme_menu\');
function thanathos_theme_display_callback(){
echo "Johny la hanta este mui loca";
}
add_action(\'admin_init\' , \'thanatos_initializa_theme_options\');
function thanatos_initializa_theme_options(){
add_settings_section(
\'general_settings_section\',
\'Thanatos Options\',
\'thanatos_general_options_callback\',
\'thanathos_theme_options\' //I believe this where my mistakes is
);
}
function thanatos_general_options_callback(){
echo \'mergem la mare\';
}
我使用了页面id来设置该节的放置位置,我相信thanatos\\u general\\u options\\u callback()应该显示在那里,但由于某些原因,它没有显示。我在这里做错了什么?
最合适的回答,由SO网友:byronyasgur 整理而成
我想您可能需要使用这些功能settings_fields
do_settings_sections
和register_setting
以及add_setting_section
要使其正常工作,请参见参考文献。这些功能here. 我不确定你是否能得到一个简陋的版本,把其中的一些删掉,但也许或者不。。。我知道在工作选项页面中使用了很多函数。
我建议复制一个已完成的工作选项页面,如Jeffrey way\'s offering 进入你的主题,删除东西,直到你得到一个基本的工作模型。这将帮助您理解这一点,因为它非常复杂。
它也很复杂,足以保证在您的系统上设置多个练习主题,这样,如果您是第一次尝试,您就可以尝试选项页面的不同版本/阶段。
此外,在研究中要注意“旧方法”和“新方法”的设置。设置API是“新方式”
编辑-正如Eric所说,将“管理员”作为功能是可疑的。