0

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

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

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

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

这是构建元框(父主题)选项的数组的摘录:

$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 的文件,但它没有添加额外的开始按钮选项。

$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.'
    );
4

1 回答 1

0

You could add additionnal options like this :

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

Be aware that even if you don't change the core theme. You rely on the way it is structured. So your code might still break in case of an update by the theme developer.

于 2013-04-29T08:22:20.243 回答