文章字段

文章字段的数据获取使用get_post_meta函数。

若配置数据如下:

  1. $ashu_meta[] = array(
  2.   'name' => 'Input Example',
  3.   'id'   => 'text_example', //Use the id to get data.
  4.   'desc' => 'A text input example, Default content:"Hello ashuwp."',
  5.   'std'  => 'Hello ashuwp.',
  6.   'type' => 'text',
  7.   'multiple' => false,
  8. );

获取数据:
由于配置数据中,'type'=>'checkbox'、'type'=>'group'...等配置项,保存的数据为数组,所以获取数据请使用var_dump打印数据来确定结构。

  1. <?php
  2. $meta_value = get_post_meta($post->ID,'text_example',true);
  3. var_dump($meta_value);

分类字段

文章字段的数据获取使用get_term_meta函数。

若配置数据如下:

  1. $ashu_meta[] = array(
  2.   'name' => 'Input Example',
  3.   'id'   => 'text_example', //Use the id to get data.
  4.   'desc' => 'A text input example, Default content:"Hello ashuwp."',
  5.   'std'  => 'Hello ashuwp.',
  6.   'type' => 'text',
  7.   'multiple' => false,
  8. );

获取数据:
由于配置数据中,'type'=>'checkbox'、'type'=>'group'...等配置项,保存的数据为数组,所以获取数据请使用var_dump打印数据来确定结构。

  1. <?php
  2. $meta_value = get_term_meta($term->term_id,'text_example',true);
  3. var_dump($meta_value);

设置页面

若配置数据如下:

  1. /**General options**/
  2. $page_info = array(
  3.   'full_name' => 'General Options',
  4.   'optionname'=>'general', //Use the optionname to get data.
  5.   'child'=>false,
  6.   'filename' => 'generalpage'
  7. );
  8. $ashu_options = array();
  9. $ashu_options[] = array(
  10.   'name' => 'Input Example',
  11.   'id'   => '_id_text',
  12.   'desc' => 'description or notice',
  13.   'std'  => 'Default content',
  14.   'type' => 'text'
  15. );
  16. $option_page = new ashuwp_options_feild($ashu_options$page_info);

数据保存说明:
设置页面的数据保存方式为一整个页面的所有设置数据保存在一个数组里面,存储在数据库的options表里面,如上面范例,optionname的值为general,那这个页面的数据保存在options表里面,名称为 ashuwp_general,你没看错,为了避免设置选项在数据保存时可能存在的冲突,在数据库里面保存的名称前面加了前缀“ashuwp_”。

获取数据:

  1. <?php
  2. $general_options = get_option('ashuwp_general');
  3. var_dump($general_options);

设置数据获取之后是一个多维数组,所以请先确定好数组结构再使用。