您可以尝试这样的代码
<?php
function theme_settings_init(){
register_setting( \'theme_settings\', \'theme_settings\' );
}
î这用于为自定义设置数组保留名称
//Add settings to page menu
function add_settings_page() {
add_menu_page( __( \'Contenu éditable\' ), __( \'Contenu éditable\' ), \'manage_options\', \'settings\', \'theme_settings_page\');
}
î这将在管理中创建页面
//Add Actions
add_action( \'admin_init\', \'theme_settings_init\' );
add_action( \'admin_menu\', \'add_settings_page\' );
îWordpress挂钩
//Start Setting Page
function theme_settings_page() {?>
<div>
<div id="icon-options-general"></div>
<h2 id="title"><?php _e( \'Contenu éditable\' ) //your admin panel title ?></h2>
<?php if($_GET[\'settings-updated\'] == true): ?>
<div id="message" class="updated below-h2"><p>Saved successfully</p></div>
<?php endif; ?>
<form method="post" action="options.php">
<?php settings_fields( \'theme_settings\' ); ?>
<?php $options = get_option( \'theme_settings\' );
$defaults = array(
\'viadeo\' => \'http://www.viadeo.com\',
\'linkedin\' => \'http://www.linkedin.com\',
);
?>
<table>
<tr valign="top">
<th scope="row"><?php _e( \'Lien viadeo\' ); ?></th>
<td><input id="theme_settings[viadeo]" type="text" size="40" name="theme_settings[viadeo]" value="<?php (!empty($options[\'viadeo\']))?esc_attr_e( $options[\'viadeo\'] ):esc_attr_e($defaults[\'viadeo\']); ?>" />
<?php if(empty($options[\'viadeo\'])):?>
Please hit the save button in ordrer to save the default values
<?php endif; ?>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e( \'Lien Linkedin\' ); ?></th>
<td><input id="theme_settings[linkedin]" type="text" size="40" name="theme_settings[linkedin]" value="<?php (!empty($options[\'linkedin\']))?esc_attr_e( $options[\'linkedin\'] ):esc_attr_e($defaults[\'linkedin\']); ?>" />
<?php if(empty($options[\'linkedin\'])):?>
Please hit the save button in ordrer to save the default values
<?php endif; ?>
</td>
</tr>
</table>
<p><input name="submit" id="submit" class="button button-primary" value="Save Changes" type="submit"></p>
</form>
</div>
<?php
}
î这是显示页面的代码
//validation
function options_validate( $input ) {
global $select_options, $radio_options;
if ( ! isset( $input[\'option1\'] ) )
$input[\'option1\'] = null;
$input[\'option1\'] = ( $input[\'option1\'] == 1 ? 1 : 0 );
$input[\'sometext\'] = wp_filter_nohtml_kses( $input[\'sometext\'] );
if ( ! isset( $input[\'radioinput\'] ) )
$input[\'radioinput\'] = null;
if ( ! array_key_exists( $input[\'radioinput\'], $radio_options ) )
$input[\'radioinput\'] = null;
$input[\'sometextarea\'] = wp_filter_post_kses( $input[\'sometextarea\'] );
return $input;
}
?>
最后,上面的代码将保存字段的值。
您可以在函数的底部添加此代码。php或创建一个新文件(更好的解决方案,更可读),并在函数中要求它。php
享受