首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Wordpress主题设置页面

Wordpress主题设置页面
EN

WordPress Development用户
提问于 2015-08-20 21:43:37
回答 2查看 174关注 0票数 0

我很难让我的“Hello”显示在我创建的主题页面上。这一切至少看起来都是正确的(但显然不是)--我在这里错过了什么?

代码语言:javascript
复制
// Add Theme Options to menu

function add_theme_menu_item() {

add_theme_page("Theme Panel", "Theme Panel", "manage_options", "theme-panel", "initialize_theme_options", null, 99);

}

add_action("admin_menu", "add_theme_menu_item");

 /**
 * Initializes the theme options page by registering the Sections,
  * Fields, and Settings.
 *
 * This function is registered with the 'admin_init' hook.
 */

 function initialize_theme_options() {

// First, we register a section. This is necessary since all future options must belong to one.

add_settings_section(

    // ID used to identify this section and with which to register options
    'main_settings_section',

    // Title to be displayed on the administration page
    'Main Theme Options',

    // Callback used to render the description of the section

    'main_settings_callback', 

    // Page

    'theme-panel'

);

} 

add_action('admin_init', 'initialize_theme_options');

 // end initialize_theme_options

/* ------------------------------------------------------------------------ *
* Section Callbacks
* ------------------------------------------------------------------------ */

/**
* This function provides a simple description for the General Options page. 
*
* It is called from the 'initialize_theme_options' function by being passed as a parameter
* in the add_settings_section function.
*/

function main_settings_callback() {

  echo 'Hello world.';

} 
// end main_settings_callback
EN

回答 2

WordPress Development用户

发布于 2015-08-20 22:40:45

这是错误的:

代码语言:javascript
复制
add_theme_page("Theme Panel", "Theme Panel", "manage_options", "theme-panel", "initialize_theme_options", null, 99);

最后两个参数不应该在那里。请在代码库这里中检查此函数。

编辑:

更重要的是,最后一个参数(应该在那里) initialize_theme_options也是错误的,因为它应该是对输出内容的函数的回调。例如,您的main_settings_callback函数。

第二次编辑:

它不起作用,可能是因为在add_settings_section函数的调用中传递了最后一个参数theme-panel,并且这个页面可能不存在。我说的对吗?例如,尝试用general替换这个参数,它将在主设置页面输出。

票数 1
EN

WordPress Development用户

发布于 2015-08-20 23:45:26

好的,我知道了。

https://codex.wordpress.org/Function_参考/做_设置_章节

代码语言:javascript
复制
function initialize_theme_options() {

// First, we register a section. This is necessary since all future options must belong to one.

add_settings_section(

    // ID used to identify this section and with which to register options
    'main_settings_section',

    // Title to be displayed on the administration page
    'Main Theme Options',

    // Callback used to render the description of the section

    'main_settings_callback', 

    // Page

    'theme-panel'

);

do_settings_sections('theme-panel');

} 
票数 0
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

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

复制
相关文章

相似问题

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