https://codex.wordpress.org/index.php?title=Creating_Options_Pages&oldid=97268
此页面显示如何创建选项页面。
// theme-settings.php
<?php
add_action(\'admin_menu\', \'talimiboard_register_menu_and_page\');
function talimiboard_register_menu_and_page()
{
add_theme_page(\'Talimiboard theme settings\', \'Theme Settings\', \'administrator\', \'talimiboard_theme_settings\', \'talimiboard_theme_settings\');
add_action(\'admin_init\', \'talimiboard_register_theme_settings\');
}
function talimiboard_register_theme_settings()
{
register_setting(\'talimiboard_theme_settings\', \'talimi_mapapi\');
register_setting(\'talimiboard_theme_settings\', \'talimi_smtphost\');
register_setting(\'talimiboard_theme_settings\', \'talimi_smtpport\');
register_setting(\'talimiboard_theme_settings\', \'talimi_smtpuser\');
register_setting(\'talimiboard_theme_settings\', \'talimi_smtppass\');
register_setting(\'talimiboard_theme_settings\', \'talimi_smtpfrom\');
register_setting(\'talimiboard_theme_settings\', \'talimi_parallax\');
}
function talimiboard_theme_settings()
{ ?>
<style>
th {
text-align: left;
}
.table-wrap {
margin-top: 35px;
}
</style>
<div class="wrap">
<h2 style="text-align: center;">Theme Settings</h2>
<form method="post" action="options.php">
<?php settings_fields(\'talimiboard_theme_settings\'); ?>
<div class="table-wrap">
<h3>Appearances</h3>
<table class="form-table">
<tr valign="top">
<th scope="row"><label
for="talimi_parallax">Homepage Parallax Effect</label></th>
<td><input type="checkbox" id="talimi_parallax" name="talimi_parallax"
value="1" <?php echo checked(\'1\', get_option(\'talimi_parallax\')); ?>/></td>
</tr>
</table>
</div>
<div class="table-wrap">
<h3>API Keys</h3>
<table>
<tr valign="top">
<th scope="row">Google Map API Key</th>
<td><input type="text" name="talimi_mapapi" value="<?php echo get_option(\'talimi_mapapi\'); ?>"/>
</td>
</tr>
</table>
</div>
<div class="table-wrap">
<h3>SMTP Settings</h3>
<table>
<tr valign="top">
<th scope="row">SMTP Host</th>
<td>
<input type="text" name="talimi_smtphost"
value="<?php echo get_option(\'talimi_smtphost\'); ?>"/>
</td>
</tr>
<tr>
<th scope="row">SMTP Port</th>
<td>
<input type="text" name="talimi_smtpport"
value="<?php echo get_option(\'talimi_smtpport\', 587); ?>"/>
</td>
</tr>
<tr>
<th>From</th>
<td>
<input type="text" name="talimi_smtpfrom"
value="<?php echo get_option(\'talimi_smtpfrom\'); ?>"/>
</td>
</tr>
<tr>
<th>SMTP Account</th>
<td><input type="text" name="talimi_smtpuser"
value="<?php echo get_option(\'talimi_smtpuser\'); ?>"/></td>
</tr>
<tr>
<th>Password</th>
<td><input type="password" name="talimi_smtppass"
value="<?php echo get_option(\'talimi_smtppass\'); ?>"/></td>
</tr>
</table>
</div>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e(\'Save Changes\') ?>"/>
</p>
</form>
</div>
<?php } ?>
<?php
// functions.php
require_once(get_template_directory_ur() . \'/page-templates/theme-settings.php\');
$google_map_api_key = get_option(\'talimi_mapapi\');
?>
然后echo$google\\u map\\u api\\u键什么也不显示。。