使现代化
我想出来了。我从wp-admin/options-reading.php
. 下面是示例代码。这只是添加了一个选项,选择一个页面设置为我的主题选项的首页。
add_menu_page(\'Menu Name\', \'Menu Name\', \'manage_options\', \'menu-slug\', \'menu_manage_options\');
function menu_manage_options(){
?>
<div class="wrap">
<h1><?php echo esc_html( $title ); ?></h1>
<form method="post" action="options.php">
<?php
settings_fields( \'reading\' );
if ( ! in_array( get_option( \'blog_charset\' ), array( \'utf8\', \'utf-8\', \'UTF8\', \'UTF-8\' ) ) )
add_settings_field( \'blog_charset\', __( \'Encoding for pages and feeds\' ), \'options_reading_blog_charset\', \'reading\', \'default\', array( \'label_for\' => \'blog_charset\' ) );
?>
<?php if ( ! get_pages() ) : ?>
<input name="show_on_front" type="hidden" value="posts" />
<table class="form-table">
<?php
if ( \'posts\' != get_option( \'show_on_front\' ) ) :
update_option( \'show_on_front\', \'posts\' );
endif;
else :
if ( \'page\' == get_option( \'show_on_front\' ) && ! get_option( \'page_on_front\' ) && ! get_option( \'page_for_posts\' ) )
update_option( \'show_on_front\', \'posts\' );
?>
<table class="form-table">
<tr>
<th scope="row"><?php _e( \'Front page displays\' ); ?></th>
<td id="front-static-pages"><fieldset><legend class="screen-reader-text"><span><?php _e( \'Front page displays\' ); ?></span></legend>
<p><label>
<input name="show_on_front" type="radio" value="page" class="tog" <?php checked( \'page\', get_option( \'show_on_front\' ) ); ?> />
<?php printf( __( \'A <a href="%s">static page</a> (select below)\' ), \'edit.php?post_type=page\' ); ?>
</label>
</p>
<ul>
<li><label for="page_on_front"><?php printf( __( \'Front page: %s\' ), wp_dropdown_pages( array( \'name\' => \'page_on_front\', \'echo\' => 0, \'show_option_none\' => __( \'— Select —\' ), \'option_none_value\' => \'0\', \'selected\' => get_option( \'page_on_front\' ) ) ) ); ?></label></li>
</ul>
<?php if ( \'page\' == get_option( \'show_on_front\' ) && get_option( \'page_for_posts\' ) == get_option( \'page_on_front\' ) ) : ?>
<div id="front-page-warning" class="error inline"><p><?php _e( \'<strong>Warning:</strong> these pages should not be the same!\' ); ?></p></div>
<?php endif; ?>
</fieldset></td>
</tr>
<?php endif; ?>
<?php do_settings_fields( \'reading\', \'default\' ); ?>
</table>
<?php do_settings_sections( \'reading\' ); ?>
<?php submit_button(); ?>
</form>
</div>
<?php
}