通过带有文本框的选项页存储数组


Store an array through the option page with text box

我在Wordpress中做了一个选项页。我有一个文本框,把一个值放在一个id中。现在我想在一个id中存储一个值数组。我在主题选项中存储一个文本的代码。

array(  "name" => __('Text'),
                    "desc" => __('Your Text username, to be used on the links'),
                    "id" => $shortname."_test",
                    "std" => "Tset",
                    "type" => "text"),

保存文本框中的数据

case 'text':
        ?>
        <tr valign="top"> 
            <th scope="row"><label for="<?php echo $value['id']; ?>"><?php echo __($value['name'],'twentyeleven'); ?></label></th>
            <td>
                <input name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php if ( get_option( $value['id'] ) != "") { echo get_option( $value['id'] ); } else { echo $value['std']; } ?>" />
                <?php echo __($value['desc'],'twentyeleven'); ?>
            </td>
        </tr>

我想创建更多的文本字段并保存在一个ID中。

序列化数组,或Json对其进行编码。

这将有效地将数组以字符串的形式存储在选项表的相应ID下。当您拉动该选项时,您可以取消序列化或Json将该选项解码回数组。

Json编码/解码通常是首选,但请记住,在解码时,它默认为Object类型。将调用Json Decode中的第二个参数设置为true,以便将其作为关联数组返回。