我必须在我的自定义主题wordpress中创建一个选项页。下面是一个代码示例
<?php
function bguru_register_settings(){
$default_options=array(
\'bguru_logo\'=>\'http://templategraphy.com/demo/businessguru/images/logo.png\',
\'bguru_vimeo\'=>\'\',
\'bguru_skype\'=>\'\',
\'bguru_dribbble\'=>\'\',
\'bguru_slide_one_image\'=>\'\',
\'bguru_slide_one_heading\'=>\'\',
\'bguru_slide_one_text\'=>\'\'
);
add_option(\'bguru_options\',$default_options);
register_setting(\'tgbusinessguru\', \'bguru_options\');
}
add_action(\'admin_init\', \'bguru_register_settings\');
function bguru_register_options_page(){
add_theme_page(\'Business Guru Options\', \'Theme Customizer\', \'edit_theme_options\', \'bguru-options\', \'bguru_options_page\');
}
add_action(\'admin_menu\', \'bguru_register_options_page\');
function bguru_options_page(){
$options=get_option(\'bguru_options\');
?>
<div class="wrap">
<?php
screen_icon(); ?>
<h1>Business Guru Options</h1>
<form method="post" action="options.php">
<?php
settings_fields(\'tgbusinessguru\'); ?>
<table class="form-table">
<tr valign="top">
<th><h2>General</h2><th>
</tr>
<tr valign="top">
<th scope="row"><label for="bguru_logo">Logo:</label></th>
<td><input type="text" id="bguru_logo" size="50" name="bguru_options[bguru_logo]" value="<?php echo $options[\'bguru_logo\']; ?>" /></td>
</tr>
<tr valign="top">
<th><h2>Social Links</h2><th>
</tr>
<tr valign="top">
<th scope="row"><label for="bguru_vimeo">Vimeo:</label></th>
<td><input type="text" id="bguru_vimeo" size="50" name="bguru_options[bguru_vimeo]" value="<?php echo $options[\'bguru_vimeo\']; ?>" /></td>
</tr>
<tr valign="top">
<th scope="row"><label for="bguru_skype">Skype:</label></th>
<td><input type="text" id="bguru_skype" size="50" name="bguru_options[bguru_skype]" value="<?php echo $options[\'bguru_skype\']; ?>" /></td>
</tr>
<tr valign="top">
<th scope="row"><label for="bguru_dribbble">Dribbble:</label></th>
<td><input type="text" id="bguru_dribbble" size="50" name="bguru_options[bguru_dribbble]" value="<?php echo $options[\'bguru_dribbble\']; ?>" /></td>
</tr>
<tr valign="top">
<th scope="row"><label for="bguru_slide_one_image">Image:</label></th>
<td><input type="text" id="bguru_slide_one_image" size="50" name="bguru_options[bguru_slide_one_image]" value="<?php
echo $options[\'bguru_slide_one_image\']; ?>" /></td>
</tr>
<tr valign="top">
<th scope="row"><label for="bguru_slide_one_heading">Heading:</label></th>
<td><input type="text" id="bguru_slide_one_heading" size="50" name="bguru_options[bguru_slide_one_heading]" value="<?php
echo $options[\'bguru_slide_one_heading\']; ?>" /></td>
</tr>
<tr valign="top">
<th scope="row"><label for="bguru_slide_one_text">Description:</label></th>
<td><textarea type="text" id="bguru_slide_one_text" style="width:439px;height:100px;" name="bguru_options[bguru_slide_one_text]"><?php echo $options[\'bguru_slide_one_text\']; ?></textarea></td>
</tr>
</table>
<?php submit_button(); ?>
</form>
</div>
<?php } ?>
所有表单详细信息都通过仪表板传递。如果管理员忘记填充徽标字段,则默认情况下,此$default\\u选项有效,因此默认情况下徽标字段填充,但当我尝试使用get\\u选项访问阵列时,我没有得到预期的结果。