主题自定义API不会在页面

时间:2016-04-07 14:39:50

标签: php wordpress

我正在尝试为我的wordpress主题构建自定义页面。我的functions.php文件看起来像这样,工作完美:

function pu_theme_menu()
{
    add_theme_page( 'My Theme Option', 'My Theme Options', 'manage_options', 'pu_theme_options.php', 'pu_theme_page');  
}
add_action('admin_menu', 'pu_theme_menu');


function pu_theme_page()
{
?>
<div class="section panel">
    <h1>Custom Theme Options</h1>
    <form method="post" enctype="multipart/form-data" action="options.php">
        <?php 
    settings_fields('pu_theme_options'); 

    do_settings_sections('pu_theme_options.php');
        ?>
        <p class="submit">
            <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
        </p>

    </form>

     </div>
<?php
}


add_action( 'admin_init', 'pu_register_settings' );


function pu_register_settings()
{
    register_setting( 'pu_theme_options', 'pu_theme_options');    

    add_settings_section( 'header_section', 'HEADER', 'pu_display_setting', 'pu_theme_options.php' );

    $field_args = array(
      'type'      => 'text',
      'id'        => 'pu_textbox',
      'name'      => 'pu_textbox',
      'desc'      => 'Example of textbox description',
      'std'       => '',
      'label_for' => 'pu_textbox',
      'class'     => 'css_class'
    );

    add_settings_field( 'example_textbox', 'Current Logo Text', 'pu_display_setting', 'pu_theme_options.php', 'header_section', $field_args );


}


function pu_display_setting($args)
{
    extract( $args );

    $option_name = 'pu_theme_options';

    $options = get_option( $option_name );


    switch ( $type ) {  
        case 'text':  
            $options[$id] = stripslashes($options[$id]);  
            $options[$id] = esc_attr( $options[$id]);  
            echo "<input class='regular-text$class' type='text' id='$id' name='" . $option_name . "[$id]' value='$options[$id]' />";  
            echo ($desc != '') ? "<br /><span class='description'>$desc</span>" : "";  
            break;  
    }
}

但新值未显示在我的header.php

 <div class="col-lg-6 col-md-6 hidden-sm hidden-xs" id="myid">
         <?php echo $options['pu_textbox']; ?>
  </div>

我错过了什么,有人可以帮忙吗?

0 个答案:

没有答案