0

嗨,我刚刚学习使用设置 API,我似乎无法进入同一页面上的部分工作。第一部分完美地工作并保存了一天,但第二部分在保存时显示错误:

Options Page not Found

这是我的整个选项页面的代码:

    <?php 
/* ------------------------------------------------------------------------ * 
 * REGISTER MENU AND SUBMENU
 * ------------------------------------------------------------------------ */
    function thanathos_theme_menu(){
        add_menu_page('Thanathos', 
                      'Thanathos', 
                      'administrator', 
                      'thanathos_menu_id',
                      'thanathos_display'
                     );   
    }
    add_action('admin_menu' ,'thanathos_theme_menu');

 /*------------------------------------------------------------------------ * 
 * Social & Logo Options
 * ------------------------------------------------------------------------ */
 function thanathos_initialize_frontpage_options(){
        if(false == get_option('thanathos_front_page_options')){
            add_option('thanathos_front_page_options');
        }     
        add_settings_section(
                'thanathos_front_page',
                '',
                'thanathos_front_page_section_callback',
                'thanathos_front_page_options'
        );
        add_settings_field(
                'logo_path',
                'Logo Path',
                'thanathos_logo_path_url_callback',
                'thanathos_front_page_options',
                'thanathos_front_page'
        );
        register_setting(
                    'thanathos_front_page_options', 
                    'thanathos_front_page_options',
                    'thanathos_front_page_options_sanitize'
                );
    }
    add_action('admin_init', 'thanathos_initialize_frontpage_options'); 
    function thanathos_front_page_section_callback(){}

    function thanathos_logo_path_url_callback(){
        $options = get_option('thanathos_front_page_options');
        echo  '<input type="text" id="logo" name="thanathos_front_page_options[logo_path]" value="' . $options['logo_path'] . '" />';      
    }
    function thanathos_front_page_options_sanitize($input){
        $output = array();
        foreach ($input as $key => $val){
            if(isset($input[$key])){
                $output[$key] = strip_tags(stripslashes($input[$key])); 
            }
        }
        return apply_filters('thanathos_front_page_options' , $output , $input);
    }
    /* ------------------------------------------------------------------------ * 
    * Slider Options
    * ------------------------------------------------------------------------ */
     function thanathos_front_page_slider_options(){
          if(false == get_option('thanathos_front_page_slider')){
               add_option('thanathos_front_page_slider');
          }
          add_settings_section('thanathos_front_page_slider',
                               '',
                               'thanathos_front_page_slider_callback',
                               'thanathos_display',
                               'thanathos_front_page_slider'
                              );
     }
     add_action('admin_init', 'thanathos_front_page_slider_options');
     function thanathos_front_page_slider_callback(){}

/* ------------------------------------------------------------------------ * 
 * Display on Thanathos Menu Page
 * ------------------------------------------------------------------------ */
    function thanathos_display(){
?>      <style>
            fieldset{
                border:1px solid #ddd;
                margin-top:20px;
                padding-bottom: 20px;
            }
            legend{
                margin-left:5px; 
                padding:0 5px;
                color:#2481C6; 
                text-transform:uppercase;
            }
            p.submit{
                margin-left: 10px;
            }
            td input{
                width:360px;
            }
        </style>
        <div class="wrap">
            <div id="icon-themes" class="icon32"></div>
            <h2>Thanathos General Options</h2>
            <?php settings_errors(); ?>   
            <form method="post" action="options.php">
                <fieldset>
                    <legend><strong>Logo and Social Options</strong></legend>
                        <?php
                         settings_fields( 'thanathos_front_page_options' );
                         do_settings_sections( 'thanathos_front_page_options' );
                        ?>
                </fieldset>
                <?php submit_button(); ?>
            </form>
             <form method="post" action="options.php">
                <fieldset>
                    <legend><strong>Slider Options</strong></legend>
                        <?php
                         settings_fields( 'thanathos_front_page_slider' );
                         do_settings_sections( 'thanathos_front_page_slider' );
                        ?>
                </fieldset>
                <?php submit_button(); ?>
            </form>
        </div>
<?php
    }   
?>

如果这不是将两个部分添加到同一页面的正确方法,那是什么?

4

1 回答 1

2

以下是设置 api 的优秀教程。如果你想把它作为一个整体来做,那就有点长了。
第 5 部分中,它解释了为什么一页上不能有 2 个 settings_sections。
解决方案:使用标签。
这将帮助您解决问题。

http://wp.tutsplus.com/tutorials/the-complete-guide-to-the-wordpress-settings-api-part-1/

于 2012-08-23T11:05:30.853 回答