我目前正在处理Wordpress主题的主题选项页面。
作为基础,我正在使用Ian Steward的“SAMPLE WORDPRESS THEME OPTIONS PAGE”:
我已经实现了两组收音机按钮,如下所示:
他们按计划工作,应用所选择的选项。
唯一的问题:保存所选的单选按钮后不再选择。
对于上图:如果我要更改两个单选按钮并单击保存,则只有在页面再次加载后才会选择第一个单选按钮。
来自theme-options.php:
// Normal/Fixed Navigation Options
$fixed_navigation_options = array(
'Normal' => array(
'value' => ' ',
'label' => __( 'Normal', 'arrowcatch' )
),
'Fixed' => array(
'value' => 'is-fixed',
'label' => __( 'Fixed', 'arrowcatch' )
)
);
// Full-width/Contained Navigation Options
$contained_navigation_options = array(
'Full-width' => array(
'value' => ' ',
'label' => __( 'Full-width', 'arrowcatch' )
),
'Contained' => array(
'value' => 'is-contained',
'label' => __( 'Contained', 'arrowcatch' )
)
);
function arrowcatch_theme_options_page() {
global $select_options, $fixed_navigation_options, $contained_navigation_options;
if ( ! isset( $_REQUEST['settings-updated'] ) )
$_REQUEST['settings-updated'] = false; ?>
<div class="wrap">
<?php if ( false !== $_REQUEST['settings-updated'] ) : ?>
<div class="updated fade">
<p><strong>Options saved!</strong></p>
</div>
<?php endif; ?>
<!-- Normal/Fixed Navigation -->
<tr valign="top"><th scope="row"><?php _e( 'Navigation Normal/Fixed', 'arrowcatch' ); ?></th>
<td>
<fieldset><legend class="screen-reader-text"><span><?php _e( 'Navigation Normal/Fixed', 'arrowcatch' ); ?></span></legend>
<?php
if ( ! isset( $checked ) )
$checked = '';
foreach ( $fixed_navigation_options as $option ) {
$fixed_navigation_setting = $options['fixed_navigation'];
if ( '' != $fixed_navigation_setting ) {
if ( $options['fixed_navigation'] == $option['value'] ) {
$checked = "checked=\"checked\"";
} else {
$checked = '';
}
}
?>
<label class="description"><input type="radio" name="arrowcatch_theme_options[fixed_navigation]" value="<?php esc_attr_e( $option['value'] ); ?>" <?php echo $checked; ?> /> <?php echo $option['label']; ?></label><br />
<?php
}
?>
</fieldset>
</td>
</tr>
<!-- Full-width/Contained Navigation -->
<tr valign="top"><th scope="row"><?php _e( 'Navigation Full-width/Contained', 'arrowcatch' ); ?></th>
<td>
<fieldset><legend class="screen-reader-text"><span><?php _e( 'Navigation Full-width/Contained', 'arrowcatch' ); ?></span></legend>
<?php
if ( ! isset( $checked ) )
$checked = '';
foreach ( $contained_navigation_options as $option ) {
$contained_navigation_setting = $options['contained_navigation'];
if ( '' != $contained_navigation_setting ) {
if ( $options['fixed_navigation'] == $option['value'] ) {
$checked = "checked=\"checked\"";
} else {
$checked = '';
}
}
?>
<label class="description"><input type="radio" name="arrowcatch_theme_options[contained_navigation]" value="<?php esc_attr_e( $option['value'] ); ?>" <?php echo $checked; ?> /> <?php echo $option['label']; ?></label><br />
<?php
}
?>
</fieldset>
</td>
</tr>
希望这是所需的所有代码。
不确定那里发生了什么。
我非常感谢任何朝着正确方向的努力。
谢谢!