Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用WordPress API为选定字段设置默认设置?_Php_Wordpress_Wordpress Theming - Fatal编程技术网

Php 如何使用WordPress API为选定字段设置默认设置?

Php 如何使用WordPress API为选定字段设置默认设置?,php,wordpress,wordpress-theming,Php,Wordpress,Wordpress Theming,std是未设置的选项的默认值。我只需要选择字段的默认值。我试过很多东西,但似乎都不管用。我真的需要帮助。我不知道从哪里开始 因此,在这里,我使用我的函数将设置添加到我的选项页面 function nl_register_function_name() { // Validation callback register_setting( 'nl_theme_options', 'nl_t

std是未设置的选项的默认值。我只需要选择字段的默认值。我试过很多东西,但似乎都不管用。我真的需要帮助。我不知道从哪里开始

因此,在这里,我使用我的函数将设置添加到我的选项页面

                function nl_register_function_name() {
                    // Validation callback
                    register_setting( 'nl_theme_options', 'nl_theme_options', 'nl_validate_settings' );
                    // Add setting to section
                    add_settings_section( 'nl_styling_section', 'Styling', 'nl_display_styling_section', 'nl_theme_options.php' );
                    // Create selection field
                    $field_args = array(
                        'type'      => 'select',
                        'id'        => 'nl_function_name',
                        'name'      => 'nl_function_name',
                        'desc'      => 'Select border bottom size.',
                        'std'       => 'Small',
                        'label_for' => 'nl_function_name',
                        'items'     => array( 
                            "None",
                            "Small",
                            "Medium",
                            "Large"
                        )
                    );
                    // Label
                    add_settings_field( 'label_function_name', 'function_name', 'nl_display_setting', 'nl_theme_options.php', 'nl_styling_section', $field_args );
                }
                // Registers the setting
                add_action( 'admin_init', 'nl_register_function_name' );
在这里,我为select字段创建HTML

        function nl_display_setting ( $args ) {
            extract( $args );
            $option_name = 'nl_theme_options';
            $options = get_option( $option_name );
            switch ( $args['type'] ) {  
                case 'select':
                    if( isset( $options[$id] ) ) {
                        $options[$id] = stripslashes( $options[$id] );
                        $options[$id] = esc_attr( $options[$id] );
                        echo "<select name='" . $option_name . "[$id]' value='$options[$id]'>";
                        foreach( $items as $item ) {
                            $selected = ($options[$id]==$item) ? 'selected="selected"' : '';
                            echo "<option value='$item' $selected>$item</option>";
                        }
                    } elseif ( !isset( $options[$id] ) ) {
                        $std = $args['std'];
                        echo "<select name='" . $option_name . "[$id]' value='$std'>";
                        foreach( $items as $item ) {
                            echo "<option value='$item'>$item</option>";
                        }
                    }
                    echo "</select>";
                    echo ($desc != '') ? "<br><span class='description'>$desc</span>" : "";  
                break;
            }
        }
函数nl\u显示\u设置($args){
摘录($args);
$option_name='nl_主题_选项';
$options=获取选项($option\u name);
开关($args['type']){
案例“选择”:
if(isset($options[$id])){
$options[$id]=stripslashes($options[$id]);
$options[$id]=esc_attr($options[$id]);
回声“;
foreach($items作为$item){
$selected=($options[$id]==$item)?'selected=“selected”:'';
回显“$item”;
}
}elseif(!isset($options[$id])){
$std=$args['std'];
回声“;
foreach($items作为$item){
回显“$item”;
}
}
回声“;
echo($desc!='')“
$desc”:”; 打破 } }

如何使用WordPress API为选定字段设置默认设置?

我修复了它!我将在这里为将来可能有同样问题的其他人发布解决方案,因为在线上似乎没有任何解决方案

                case 'select':
                    if( isset( $options[$id] ) ) {
                        $options[$id] = stripslashes( $options[$id] );
                        $options[$id] = esc_attr( $options[$id] );
                        echo "<select name='" . $option_name . "[$id]' value='$options[$id]'>";
                        foreach( $items as $item ) {
                            $selected = ($options[$id]==$item) ? 'selected="selected"' : '';
                            echo "<option value='$item' $selected>$item</option>";
                        }
                    } elseif ( !isset( $options[$id] ) ) {
                        echo "<select name='" . $option_name . "[$id]' value='$std'>";
                        foreach( $items as $item ) {
                            $selected = ($std==$item) ? 'selected="selected"' : '';
                            echo "<option value='$item' $selected>$item</option>";
                        }
                    }
                    echo "</select>";
                    echo ($desc != '') ? "<br><span class='description'>$desc</span>" : "";  
                break;
案例“选择”:
if(isset($options[$id])){
$options[$id]=stripslashes($options[$id]);
$options[$id]=esc_attr($options[$id]);
回声“;
foreach($items作为$item){
$selected=($options[$id]==$item)?'selected=“selected”:'';
回显“$item”;
}
}elseif(!isset($options[$id])){
回声“;
foreach($items作为$item){
$selected=($std==$item)?'selected=“selected”:'';
回显“$item”;
}
}
回声“;
echo($desc!='')?“
$desc”:”; 打破
+1,完全忘记了程序性Spegettiesh Wordpress的功能