Php 如何将单选按钮变量输出到前端-wordpress

Php 如何将单选按钮变量输出到前端-wordpress,php,wordpress,forms,radio-button,wordpress-theming,Php,Wordpress,Forms,Radio Button,Wordpress Theming,我正在处理我的主题选项面板(在管理/后端),我正在努力使用单选按钮。 我遵循了本教程:用于创建单选按钮。它们现在在主题选项中,但我不知道如何将其输出到主题前端 我只想尝试回显单选按钮表单的值,但我不知道保存它的变量的名称。 通常在php中,我会这样做:if($\u POST['NAME']==“VALUE1”){echo“这里的一些文本”} 对于文本字段,我只使用它:(例如header.php中) 在functions.php中,我有: function csscolor_setting() {



我正在处理我的主题选项面板(在管理/后端),我正在努力使用单选按钮。

我遵循了本教程:用于创建单选按钮。它们现在在主题选项中,但我不知道如何将其输出到主题前端

我只想尝试
回显单选按钮表单的值,但我不知道保存它的变量的名称。

通常在php中,我会这样做:
if($\u POST['NAME']==“VALUE1”){echo“这里的一些文本”}


对于文本字段,我只使用它:
(例如header.php中)
在functions.php中,我有:

function csscolor_setting() {

    $options = get_option('theme_options');  echo "<input name='theme_options[csscolor_setting]' type='text' value='{$options['csscolor_setting']}' />";

}

为单选按钮字段创建选项


创建示例单选按钮字段


然后还有一些关于净化和验证的代码,但我认为它不应该对表单中的变量有任何影响


提前感谢。

在前端,您可以使用与“获取主题”选项功能相同的功能,即:

get_option( 'YourTheme_theme_options' );

看看这个:

谢谢你的回答。实际上,我还需要在checked单选按钮的值中添加更多的代码

我在前端的代码(例如footer.php)如下所示:

<?php $YourTheme_theme_options = get_option('YourTheme_theme_options');
echo $YourTheme_theme_options['sample_radio_buttons']; ?>


我希望这将有助于开发主题选项页面。

Wordpress在PHP上运行,但本身不是PHP。是wordpress。
function YourTheme_sample_radio_button_choices() {

    $sample_radio_buttons = array(

        'yes' => array(

            'value' => 'yes',

            'label' => 'Yes'

        ),

        'no' => array(

            'value' => 'no',

            'label' => 'No'

        ),

    );

    return apply_filters( 'YourTheme_sample_radio_button_choices', $sample_radio_buttons );

}
function YourTheme_settings_field_sample_radio_buttons() {

    $options = YourTheme_get_theme_options();

    foreach ( YourTheme_sample_radio_button_choices() as $button ) {

    ?>

    <div class="layout">

        <label class="description">

            <input type="radio" name="YourTheme_theme_options[sample_radio_buttons]" value="<?php echo esc_attr( $button['value'] ); ?>" <?php checked( $options['sample_radio_buttons'], $button['value'] ); ?> />

            <?php echo $button['label']; ?>

        </label>

    </div>

    <?php

    }

}
function YourTheme_get_theme_options() {

        $saved = (array) get_option( 'YourTheme_theme_options' );

        $defaults = array(

            'sample_checkbox'       => 'off',

            'sample_text_input'     => '',

            'sample_select_options' => '',

            'sample_radio_buttons'  => 'yes',

            'sample_textarea'       => '',

        );

        $defaults = apply_filters( 'YourTheme_default_theme_options', $defaults );

        $options = wp_parse_args( $saved, $defaults );

        $options = array_intersect_key( $options, $defaults );

        return $options;

    }
get_option( 'YourTheme_theme_options' );
<?php $YourTheme_theme_options = get_option('YourTheme_theme_options');
echo $YourTheme_theme_options['sample_radio_buttons']; ?>