从数组外部添加数组中的键值

时间:2013-04-29 06:35:42

标签: php arrays wordpress multidimensional-array wordpress-theming

这是一个php问题,恰好涉及Wordpress。

我的Wordpress父主题添加了自定义元数据盒。我需要向元数据库添加其他选项,但我需要在我的子主题中添加键值选项...而不是在创建数组的父主题中。

在父主题中添加其他选项(键值)很简单,但核心主题文件必须更改,因此在主题开发人员更新partent主题时会中断。

所以我创建了一个处理我所有自定义添加的子主题...但我不知道如何将关键值注入到父主题中包含的数组中。

以下是为元数据(父主题)构建选项的数组的摘录:

$page_meta_boxes = array(
    "Page Item" => array(
        'item'=>'page-option-item-type' ,
        'size'=>'page-option-item-size', 
        'xml'=>'page-option-item-xml', 
        'type'=>'page-option-item',
        'name'=>array(

            'home-page-featured'=>array(
                'main-title'=>array(
                    'title'=> 'MAIN TITLE',
                    'name'=> 'page-option-item-featured-text-title',
                    'type'=> 'inputtext'),
                'main-caption'=>array(
                    'title'=> 'MAIN CAPTION',
                    'name'=> 'page-option-item-stunning-text-caption',
                    'type'=> 'textarea'),
            ),
        )
    ),
)

我想在元数据库中添加其他选项,例如:

                'get-started-button-title'=>array(
                    'title'=> 'GETTING STARTED BUTTON TITLE',
                    'name'=> 'page-option-item-featured-text-button-title',
                    'type'=> 'inputtext',
                    'description'=> 'The stunning text button will appear if this field is not a blank.'),
                'get-started-button-link'=>array(
                    'title'=> 'GETTING STARTED BUTTON LINK',
                    'name'=> 'page-option-item-featured-text-button-link',
                    'type'=> 'inputtext',
                    'description'=> 'This is a stunning text button link url. This field will be ignored when button title equals to blank.'),

这甚至可能吗?

更新: 到目前为止我尝试了什么

我在我的子主题中包含一个名为options.php的文件,但它没有添加额外的get-started-button选项。

$page_meta_boxes['Page Item']['name']['home-page-featured']['get-started-button-title'] = array(
    'title'=> 'GETTING STARTED BUTTON LINK',
    'name'=> 'page-option-item-featured-text-button-link',
    'type'=> 'inputtext',
    'description'=> 'This is a stunning text button link url. This field will be ignored when button title equals to blank.'
    );

1 个答案:

答案 0 :(得分:0)

您可以添加以下附加选项:

$page_meta_boxes['Page Item']['name']['home-page-featured']['get-started-button-title'] = array(....); 

请注意,即使您不更改核心主题。你依赖于它的结构方式。因此,如果主题开发人员进行更新,您的代码可能仍会中断。