高级自定义字段给了我这个大数组。我希望能够使用php包含或要求更有效地管理这些代码块,即:包括"标题代码","谷歌分析"等。这些数组可能会变得非常大,管理它们正在成为wordpress主题开发的关键部分(无论如何对我来说)。
这些数组在wordpress中创建字段。我希望能够打开和关闭字段。我构建的某些站点字段不是必需的。如果文件更小且更易于管理,我可以很容易地看到什么是必需的,什么是不需要的。
有没有办法管理这些大数组?,因为简单地使用包含来包含代码块是行不通
的。<?php
if(function_exists("register_field_group")) {
register_field_group(array (
'id' => 'acf_options',
'title' => 'acf options',
'fields' => array (
// header code
array (
'key' => 'field_header_code',
'label' => 'header code',
'name' => 'header_code',
'type' => 'textarea',
'column_width' => '',
'instructions' => 'use for google fonts',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
// google analytics
array (
'key' => 'field_google_analytics',
'label' => 'Google analytics',
'name' => 'google_analytics',
'type' => 'textarea',
'column_width' => '',
'instructions' => 'Dont include script tags',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
// footer js
array (
'key' => 'field_before_closing_body_js',
'label' => 'Footer js - before closing body tag',
'name' => 'before_closing_body_js',
'type' => 'textarea',
'column_width' => '',
'default_value' => '',
'instructions' => 'Dont include script tags. footer js, Avanser js goes here',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
),
'location' => array (
array (
array (
'param' => 'options_page',
'operator' => '==',
'value' => 'general-options-global-stuff',
'order_no' => 0,
'group_no' => 0,
),
),
),
'options' => array (
'position' => 'normal',
'layout' => 'no_box',
'hide_on_screen' => array (
),
),
'menu_order' => 0,
));
}
您可以使用
serialize()
将任何对象转换为可以写入文件的字符串,然后完全按照使用unserialize()
将对象重新加载回内存中 在 php.net 上阅读有关它们的信息