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