谢谢你的回答,但这不会显示我的值!
首先,我试着像你说的那样将$选项设置为global,但它没有改变什么,我仍然无法获得值:
<p><?php global $options; echo $options[\'txt_number\']; ?></p><p><?php global $options; echo $options[\'txt_mail\']; ?></p>
还试图将
global $options = get_option(\'header_options\');
跳转此选项将修复它:
<div class="background-content"></div>
<div class="layout-header">
<h1 id=\'logo\' class="image-logo">
<a href="<?php echo home_url(); ?>"><img <?php do_shortcode(\'[sitelogo]\'); ?></a>
</h1>
<?php global $options = get_option(\'header_options\'); ?>
<div id="contact">
<p>Contact Us</p>
<p><?php echo $options[\'txt_mail\']; ?></p><p><?php echo $options[\'txt_number\']; ?></p>
</div>
</div>
也没什么!因此,我删除了我的表单表,并将其替换为节字段(在另一个主题选项页脱机时可用,但由于我联机,因此无法获得任何值):
function add_header_settings() {
add_menu_page(\'Option header\', \'Options header\', \'manage_options\', \'edit_header\', \'header_edit_page\', null, 58);
}
add_action(\'admin_menu\', \'add_header_settings\');
function header_edit_page() {
?>
<div id="theme-options-wrap">
<div class="icon32" id="icon-tools"> <br> </div>
<h2>Option Header</h2>
<p>Description</p>
<form method="post" action="options.php">
<?php settings_fields(\'header_options\'); ?>
<?php do_settings_sections(\'edit_header\'); ?>
<p class="submit">
<input name="Submit" type="submit" class="button-primary" value="<?php esc_attr_e(\'Save Changes\'); ?>" />
</p>
</form>
</div>
<?php }
function register_and_build_fields(){
register_setting( \'header_options\', \'header_options\', \'validate_setting\');
add_settings_section(\'homepage_settings\', \'Homepage Settings\', \'section_homepage\', \'edit_header\');
function section_homepage() {}
add_settings_field(\'number1\', \'Enter your number\', \'number_setting\', \'edit_header\', \'homepage_settings\');
}
add_action(\'admin_init\', \'register_and_build_fields\');
function validate_setting($header_options) {
return $header_options;
}
function number_setting() {
$options = get_option(\'header_options\'); echo "<input name=\'header_options[number_setting]\' type=\'text\' value=\'{$options[\'number_setting\']}\' />";
}
// $options = get_option(\'header_options\');
/* <table class="form-table">
<tr>
<th scope="row">Mail</th>
<td>
<input type="text" name="header_options[txt_mail]" value="<?php echo $options[\'txt_mail\']; ?>" />
</td>
</tr>
<tr>
<th scope="row">Phone number</th>
<td>
<input type="text" name="header_options[txt_number]" value="<?php echo $options[\'txt_number\']; ?>" />
</td>
</tr>
</table>
function header_validate_options($input) {
$input[\'txt_mail\'] = wp_filter_nohtml_kses($input[\'txt_mail\']);
$input[\'txt_number\'] = wp_filter_nohtml_kses($input[\'txt_number\']);
return $input;
} */
function header_add_content() {
global $options;
$options = get_option(\'header_options\');
}
add_filter("the_content", "header_add_content");
同样,我可以在主题选项页面中保存我的值,但前端不想获取它们:/
顺便说一下:<div class="icon32" id="icon-tools"> <br> </div>
我多次看到这段代码,但标题旁边没有任何图标(即使是在我的第二台新安装的计算机上),这是因为WP的更新吗?
EDIT :
当我执行
get_option
使用另一个变量
$options
喜欢
$header_options
或者随便什么,谢谢你的帮助!
如果有人对图标问题有什么解释,我还是想听!