0
我是新來的PHP,我想在wordpress中創建一個主題選項。的主題選項其餘都工作正常,但我創造了選項3沒有顯示在前端的文字Wordpress主題選項文本區域不在前端顯示文本
<?php
//register settings
function theme_settings_init(){
register_setting('theme_settings', 'theme_settings');
}
//add settings page to menu
function add_settings_page() {
add_menu_page(__('Theme Settings'), __('Theme Settings'), 'manage_options', 'settings', 'theme_settings_page');
}
//add actions
add_action('admin_init', 'theme_settings_init');
add_action('admin_menu', 'add_settings_page');
//define your variables
$color_scheme = array('default','blue','green',);
//start settings page
function theme_settings_page() {
if (! isset($_REQUEST['updated']))
$_REQUEST['updated'] = false;
//get variables outside scope
global $color_scheme;
?>
<div>
<div id="icon-options-general"></div>
<h2><?php _e('Elegant Theme Settings') //your admin panel title ?></h2>
<?php
//show saved options message
if (false !== $_REQUEST['updated']) : ?>
<div><p><strong><?php _e('Options saved'); ?></strong></p></div>
<?php endif; ?>
<form method="post" action="options.php">
<?php settings_fields('theme_settings'); ?>
<?php $options = get_option('theme_settings'); ?>
<table>
<!-- Option 1: Custom Logo -->
<tr valign="top">
<th scope="row"><?php _e('Custom Logo'); ?></th>
<td><input id="theme_settings[custom_logo]" type="text" size="36" name="theme_settings[custom_logo]" value="<?php esc_attr_e($options['custom_logo']); ?>" />
<label for="theme_settings[custom_logo]"><?php _e('Enter the URL to your custom logo'); ?></label></td>
</tr>
<!-- Option 2: Color Scheme -->
<tr valign="top">
<th scope="row"><?php _e('Color Scheme'); ?></th>
<td><select name="theme_settings[color_scheme]">
<?php foreach ($color_scheme as $option) { ?>
<option <?php if ($options['color_scheme'] == $option){ echo 'selected="selected"'; } ?>><?php echo htmlentities($option); ?></option>
<?php } ?>
</select>
<label for="theme_settings[color_scheme]"><?php _e('Choose Your Color Scheme'); ?></label></td>
</tr>
<!-- Option 3: Intro Code -->
<tr valign="top">
<th scope="row"><?php _e('Intro'); ?></th>
<td><label for="theme_settings[headline]"><?php _e('Enter your Intro Headline'); ?></label>
<br />
<textarea id="theme_settings[headline]" name="theme_settings[headline]" rows="5" cols="36"><?php esc_attr_e($options['headline']); ?></textarea></td>
</tr>
<!-- Option 4: Tracking Code -->
<tr valign="top">
<th scope="row"><?php _e('Tracking Code'); ?></th>
<td><label for="theme_settings[tracking]"><?php _e('Enter your analytics tracking code'); ?></label>
<br />
<textarea id="theme_settings[tracking]" name="theme_settings[tracking]" rows="5" cols="36"><?php esc_attr_e($options['tracking']); ?></textarea></td>
</tr>
</table>
<p><input name="submit" id="submit" value="Save Changes" type="submit"></p>
</form>
</div><!-- END wrap -->
<?php
}
//sanitize and validate
function options_validate($input) {
global $select_options, $radio_options;
if (! isset($input['option']))
$input['option'] = null;
$input['option'] = ($input['option'] == 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 //show tracking code for the header
echo $options['headline'];?>
請幫我