theme options not saving

时间:2014-02-14 作者:dannyw24

我创建了一个非常简单的主题设置页面,让我的用户可以添加一些社交媒体链接。然而,当我输入一些数据并保存字段时,文本消失,似乎无法保存。

<?php
    // create custom theme settings menu
    add_action(\'admin_menu\', \'getextra_settings_create_menu\');

    function getextra_settings_create_menu() {

      //create new top-level menu
      add_menu_page(\'Theme Settings\', \'Theme Options\', \'administrator\', __FILE__, \'ge_settings_callback_page\');

      //call register settings function
      add_action( \'admin_init\', \'register_mysettings\' );
    }


    function register_mysettings() {
      //register our settings
      register_setting( \'theme-settings-group\', \'theme_options\' );
    }

    function ge_settings_callback_page() {
    ?>
    <div class="wrap">
    <h2>Foxyrentals Theme Settings</h2>

    <form method="post" action="options.php">
        <?php settings_fields( \'theme-settings-group\' ); ?>
        <?php do_settings_sections( \'theme-settings-group\' ); ?>
        <table class="form-table">
            <tr valign="top">
            <th scope="row">Facebook</th>
            <td><input type="text" name="facebook" value="<?php echo get_option(\'facebook\'); ?>" /></td>
             </tr>
             <tr valign="top">
            <th scope="row">Twitter</th>
            <td><input type="text" name="twitter" value="<?php echo get_option(\'twitter\'); ?>" /></td>
            </tr>
            <tr valign="top">
            <th scope="row">Pinterest</th>
            <td><input type="text" name="pinterest" value="<?php echo get_option(\'pinterest\'); ?>" /></td>
            </tr>
            <tr valign="top">
            <th scope="row">Google+</th>
            <td><input type="text" name="googleplus" value="<?php echo get_option(\'googleplus\'); ?>" /></td>
            </tr>
            <tr valign="top">
            <th scope="row">Linkedin</th>
            <td><input type="text" name="linkedin" value="<?php echo get_option(\'linkedin\'); ?>" /></td>
            </tr>
            <tr valign="top">
            <th scope="row">Foursquare</th>
            <td><input type="text" name="foursquare" value="<?php echo get_option(\'foursquare\'); ?>" /></td>
            </tr>

        </table>

        <?php submit_button(); ?>

    </form>
    </div>

    <?php } ?>
由此,我创建了一个函数,使用以下命令在页脚中显示这些选项:;

  <?php

function social_icons() {
    $facebook = get_option(\'facebook\');
    $twitter = get_option(\'twitter\');
    $googleplus = get_option(\'googleplus\');
    $linkedin = get_option(\'linkedin\');
    $foursquare = get_option(\'foursquare\');
    $pinterest = get_option(\'pinterest\');
?>
        <a href="<?php echo $facebook; ?>"<img src="<?php bloginfo(\'template_url\'); ?>/images/icon_fb.png" alt="facebook" /></a>
        <a href="<?php echo $twitter; ?>"><img src="<?php bloginfo(\'template_url\'); ?>/images/icon_tw.png" alt="twitter" /></a>
        <a href="<?php echo $googleplus; ?>"><img src="<?php bloginfo(\'template_url\'); ?>/images/google-icon.png" alt="googleplus" /></a>
        <a href="<?php echo $linkedin; ?>"><img src="<?php bloginfo(\'template_url\'); ?>/images/pinterest-icon.png" alt="pinterest" /></a>
        <a href="<?php echo $pinterest; ?>"><img src="<?php bloginfo(\'template_url\'); ?>/images/linkedin-icon.png" alt="linkedin" /></a>
        <a href="<?php echo $foursqaure; ?>"><img src="<?php bloginfo(\'template_url\'); ?>/images/foursquare-2-icon.png" alt="foursqaure" /></a>

 <?php } ?>

1 个回复
最合适的回答,由SO网友:sun 整理而成

你的register_setting() 应适用于以下所有字段

function register_mysettings() {
  //register our settings
   register_setting( \'theme-settings-group\', \'facebook\' );
   register_setting( \'theme-settings-group\', \'twitter\' );
   register_setting( \'theme-settings-group\', \'pinterest\' );
   register_setting( \'theme-settings-group\', \'googleplus\' );
  //etc

}
在所有领域都这样做,如果你有什么困难,请告诉我

结束

相关推荐

WP_Query in functions.php

我有一些代码要转换成函数。它工作得很好,直到我将其包装到所述函数中: $args = array( \'posts_per_page\' => -1, \'post_type\' => \'asset\', \'category_name\' => $cat ); $cat_query = new WP_Query( $args );