文章字段
文章字段的数据获取使用get_post_meta函数。
若配置数据如下:
- $ashu_meta[] = array(
- 'name' => 'Input Example',
- 'id' => 'text_example',
- 'desc' => 'A text input example, Default content:"Hello ashuwp."',
- 'std' => 'Hello ashuwp.',
- 'type' => 'text',
- 'multiple' => false,
- );
获取数据:
由于配置数据中,'type'=>'checkbox'、'type'=>'group'...等配置项,保存的数据为数组,所以获取数据请使用var_dump打印数据来确定结构。
- <?php
- $meta_value = get_post_meta($post->ID,'text_example',true);
- var_dump($meta_value);
分类字段
文章字段的数据获取使用get_term_meta函数。
若配置数据如下:
- $ashu_meta[] = array(
- 'name' => 'Input Example',
- 'id' => 'text_example',
- 'desc' => 'A text input example, Default content:"Hello ashuwp."',
- 'std' => 'Hello ashuwp.',
- 'type' => 'text',
- 'multiple' => false,
- );
获取数据:
由于配置数据中,'type'=>'checkbox'、'type'=>'group'...等配置项,保存的数据为数组,所以获取数据请使用var_dump打印数据来确定结构。
- <?php
- $meta_value = get_term_meta($term->term_id,'text_example',true);
- var_dump($meta_value);
设置页面
若配置数据如下:
- $page_info = array(
- 'full_name' => 'General Options',
- 'optionname'=>'general',
- 'child'=>false,
- 'filename' => 'generalpage'
- );
- $ashu_options = array();
- $ashu_options[] = array(
- 'name' => 'Input Example',
- 'id' => '_id_text',
- 'desc' => 'description or notice',
- 'std' => 'Default content',
- 'type' => 'text'
- );
- $option_page = new ashuwp_options_feild($ashu_options, $page_info);
数据保存说明:
设置页面的数据保存方式为一整个页面的所有设置数据保存在一个数组里面,存储在数据库的options表里面,如上面范例,optionname的值为general,那这个页面的数据保存在options表里面,名称为 ashuwp_general,你没看错,为了避免设置选项在数据保存时可能存在的冲突,在数据库里面保存的名称前面加了前缀“ashuwp_”。
获取数据:
- <?php
- $general_options = get_option('ashuwp_general');
- var_dump($general_options);
设置数据获取之后是一个多维数组,所以请先确定好数组结构再使用。