Skip to content

需要更详细的使用教程 #3

Description

@mochen91

CSS略懂,PHP小白一个,自己做了WP主题准备自己用,又不想来回改代码,所以打算做个后台一劳永逸。刚好在阿树博客看到这个框架,能省去不少功夫啊,不然一些自定义字段什么的都要自己写了。不过苦闷的是,相关文档里面说的不够细致,网上也找不到相关的教程,所以只能自己摸索了。我主要有三个需求,已经配置了,前段页面还没做完,一些数据不还没调用,还不知道,这里一并贴出来,希望大大能帮忙参考下。

**1.遇到问题:**后台设置更新后前台调出来的数据仍然是旧数据。后台配置代码如下:

$page_info = array(
  'full_name'  => '主题设置',
  'optionname' => 'general',
  'child'      => false,
  'filename'   => 'generalpage'
);
$ashu_options[] = array(
  'name' => '上传logo',
  'id'   => 'logo_URI',
  'desc' => '上传网站logo,尺寸200pxx50px;',
  'std'  => '',
  'button_text' => '上传',
  'type' => 'upload'
);
$option_page = new ashuwp_options_feild($ashu_options, $page_info);

前端调用代码:
<?php echo get_option('logo_URI');?>

2.怎么把做出来的设置页面放在外观菜单下,和主题一起生效?child那里怎么设置?

$page_info = array(
  'full_name'  => '主题设置',
  'optionname' => 'general',
  'child'      => false,
  'filename'   => 'generalpage'
);

配置文档里面是有说明

child - 是否为顶级页面,若设置为true,则必须设置parent_slug参数

parent_slug - 父级页面的名称,可以是使用本框架配置的页面filename的值,也可以是wordpress默认已经存在的页面,比如'parent_slug'=>'edit.php?post_type=product',设置页面将会出现在自定义文章类型product的下面。

但父级页面的名称是什么?不知道了,试了好多都不对,这些在官方文档里面列出来就好了。

3.利用array Input类型做热搜标签是否可以,我看后面的type是numbers_array,内容必须是数字吗?如果是汉字是否可以正常使用。

$ashu_options[] = array(
  'name' => 'Array Input',
  'id'   => 'array_input',
  'desc' => 'Set type as numbers array, Input numbers separated by commas, The data saved as array.',
  'type' => 'numbers_array'
);

4.在文章页面需要添加两个自定义字段,一个是相关阅读,一个是参考资料,但在config-example.php里面没有找到相应的实例,所以我就用Input And Upload Multiple改了个,把upload改成了text,不知道这样是否生效。

修改前的代码是:

$tab_meta[] = array(
  'name' => 'Input And Upload Multiple',
  'id'   => 'input_upload_multiple',
  'desc' => 'Set the type as group, Set the subtype as array, And set the multiple as true, The group fields is multiple.',
  'std'  => '',
  'subtype' => array(
    array(
      'name' => 'Link',
      'id'   => 'link',
      'desc' => 'Link for image',
      'std'  => 'Hello ashuwp.',
      'type' => 'text'
    ),
    array(
      'name' => 'Image',
      'id'   => 'image',
      'desc' => 'Pleas upload a image, Or fill the blank with image uri.',
      'std'  => '',
      'button_text' => 'Upload',
      'type' => 'upload'
    ),
  ),
  'multiple' => true,
  'type' => 'group'
);
$tab_meta[] = array(
  'type' => 'close'
);

$tab_box = new ashuwp_postmeta_feild($tab_meta, $tab_conf);

修改后的代码是:

$tab_meta[] = array(
  'name' => '参考资料',
  'id'   => 'reference_material',
  'desc' => '',//字段说明
  'std'  => '',//默认内容
  'subtype' => array(
    array(
      'name' => '链接',
      'id'   => 'reference_material_link',
      'desc' => '',
      'std'  => '',
      'type' => 'text'
    ),
    array(
      'name' => '文字说明',
      'id'   => 'reference_material_title',
      'desc' => '参考资料的标题。',
      'std'  => '',
      'type' => 'text'
    ),
  ),
  'multiple' => true,
  'type' => 'group'
);
$tab_meta[] = array(
  'type' => 'open'
);

$tab_box = new ashuwp_postmeta_feild($tab_meta, $tab_conf);

当然我把tab取消了,只保留了一个。效果是这样的:
效果图
还有这种以数组形式保存的数据怎么调用,大大能给个实例就好了。譬如把上面的参考资料排列成无序列表。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions