0

我目前正在处理我的 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>

希望这就是所有需要的代码。

不知道那里发生了什么。

我非常感谢朝着正确方向的任何推动。

谢谢!

4

0 回答 0