在admin中动态提取灵活内容子块标题

时间:2017-01-11 15:17:07

标签: php wordpress advanced-custom-fields

我正在开发一个项目,我正在创建一个在ACF 5之上运行的插件。我已经做得很好但是现在我仍然坚持这个问题:

我有一个灵活的内容字段设置,有多个子布局。我需要根据名称为每个布局添加条件逻辑。现在我通过获取他们的字段ID来做到这一点:

$field_id = $field['ID'];

$field是我的主阵列。

然后做一个简单的php switch语句,只需设置一个变量,然后我可以检查何时进行条件逻辑:

$layout = '';

switch ($field_id) {
case "19":
    $layout = "html";
    break;
case "28":
    $layout = "grid";
    break;
}

然后我只是查看$ layout的设置并从那里开始。虽然这确实有效但我不喜欢每次移动开发环境或重新创建布局时都必须更新ID。

有谁知道如何更好地做到这一点?

单个$ field的数组转储:

Array
(
[padding_top] => 0
[padding_right] => 0
[padding_bottom] => 0
[padding_left] => 0
[background_style] => default
[section_width] => default
[ID] => 28
[key] => field_5876368ea05b4
[label] => Section Styles
[name] => acf[field_5873e9fdacab1][0][field_5876368ea05b4]
[prefix] => acf[field_5873e9fdacab1][0]
[type] => section_styles
[value] => Array
    (
        [section_width] => default
        [margin_top] => 
        [margin_right] => 
        [margin_bottom] => 
        [margin_left] => 
        [padding_top] => 
        [padding_right] => 
        [padding_bottom] => 
        [padding_left] => 
        [background_color] => 
        [background_image] => 
        [background_style] => default
        [background_position_1] => top
        [background_position_2] => left
    )

[menu_order] => 0
[instructions] => 
[required] => 0
[id] => acf-field_5873e9fdacab1-0-field_5876368ea05b4
[class] => 
[conditional_logic] => 0
[parent] => 14
[wrapper] => Array
    (
        [width] => 
        [class] => 
        [id] => 
    )

[_name] => section_styles
[_prepare] => 1
[_valid] => 1
[parent_layout] => 58763683a05b3
[margin_top] => 
[margin_right] => 
[margin_bottom] => 
[margin_left] => 
[background_color] => 
[background_position_1] => top
[background_position_2] => left
)

主构建器对象的数组转储:

Array
(
[layouts] => Array
    (
        [0] => Array
            (
                [key] => 5873ea05b5bf2
                [name] => html_section
                [label] => HTML Section
                [display] => block
                [sub_fields] => Array
                    (
                        [0] => Array
                            (
                                [placement] => top
                                [endpoint] => 0
                                [ID] => 15
                                [key] => field_5873f2366de0c
                                [label] => Content
                                [name] => 
                                [prefix] => acf
                                [type] => tab
                                [value] => 
                                [menu_order] => 0
                                [instructions] => 
                                [required] => 0
                                [id] => 
                                [class] => 
                                [conditional_logic] => 0
                                [parent] => 14
                                [wrapper] => Array
                                    (
                                        [width] => 
                                        [class] => 
                                        [id] => 
                                    )

                                [_name] => 
                                [_prepare] => 0
                                [_valid] => 1
                                [parent_layout] => 5873ea05b5bf2
                            )

                        [1] => Array
                            (
                                [tabs] => all
                                [toolbar] => full
                                [media_upload] => 1
                                [default_value] => 
                                [delay] => 0
                                [ID] => 16
                                [key] => field_5873f2456de0d
                                [label] => Content
                                [name] => content
                                [prefix] => acf
                                [type] => wysiwyg
                                [value] => 
                                [menu_order] => 1
                                [instructions] => 
                                [required] => 0
                                [id] => 
                                [class] => 
                                [conditional_logic] => 0
                                [parent] => 14
                                [wrapper] => Array
                                    (
                                        [width] => 
                                        [class] => 
                                        [id] => 
                                    )

                                [_name] => content
                                [_prepare] => 0
                                [_valid] => 1
                                [parent_layout] => 5873ea05b5bf2
                            )

                        [2] => Array
                            (
                                [multiple] => 0
                                [allow_null] => 1
                                [choices] => Array
                                    (
                                        [narrow-width] => Narrow
                                        [default-width] => Default
                                        [full-width] => Full Width
                                    )

                                [default_value] => Array
                                    (
                                        [0] => default-width
                                    )

                                [ui] => 0
                                [ajax] => 0
                                [placeholder] => 
                                [return_format] => value
                                [ID] => 17
                                [key] => field_5873f2616de0e
                                [label] => Width
                                [name] => width
                                [prefix] => acf
                                [type] => select
                                [value] => 
                                [menu_order] => 2
                                [instructions] => 
                                [required] => 0
                                [id] => 
                                [class] => 
                                [conditional_logic] => 0
                                [parent] => 14
                                [wrapper] => Array
                                    (
                                        [width] => 
                                        [class] => 
                                        [id] => 
                                    )

                                [_name] => width
                                [_prepare] => 0
                                [_valid] => 1
                                [parent_layout] => 5873ea05b5bf2
                            )

                        [3] => Array
                            (
                                [placement] => top
                                [endpoint] => 0
                                [ID] => 18
                                [key] => field_5873f28e6de0f
                                [label] => Apperance
                                [name] => 
                                [prefix] => acf
                                [type] => tab
                                [value] => 
                                [menu_order] => 3
                                [instructions] => 
                                [required] => 0
                                [id] => 
                                [class] => 
                                [conditional_logic] => 0
                                [parent] => 14
                                [wrapper] => Array
                                    (
                                        [width] => 
                                        [class] => 
                                        [id] => 
                                    )

                                [_name] => 
                                [_prepare] => 0
                                [_valid] => 1
                                [parent_layout] => 5873ea05b5bf2
                            )

                        [4] => Array
                            (
                                [padding_top] => 0
                                [padding_right] => 0
                                [padding_bottom] => 0
                                [padding_left] => 0
                                [background_style] => default
                                [section_width] => default
                                [ID] => 19
                                [key] => field_5873f2976de10
                                [label] => Section Styles
                                [name] => section_styles
                                [prefix] => acf
                                [type] => section_styles
                                [value] => 
                                [menu_order] => 4
                                [instructions] => 
                                [required] => 0
                                [id] => 
                                [class] => 
                                [conditional_logic] => 0
                                [parent] => 14
                                [wrapper] => Array
                                    (
                                        [width] => 100
                                        [class] => 
                                        [id] => 
                                    )

                                [_name] => section_styles
                                [_prepare] => 0
                                [_valid] => 1
                                [margin_top] => 0
                                [margin_right] => 0
                                [margin_bottom] => 0
                                [margin_left] => 0
                                [border_top] => 0
                                [border_right] => 0
                                [border_bottom] => 0
                                [border_left] => 0
                                [border_style] => solid
                                [border_color] => 
                                [background_color] => 
                                [background_position_1] => top
                                [background_position_2] => left
                                [parent_layout] => 5873ea05b5bf2
                            )

                    )

                [min] => 
                [max] => 
            )

        [1] => Array
            (
                [key] => 58763683a05b3
                [name] => grid_section
                [label] => Grid Section
                [display] => block
                [sub_fields] => Array
                    (
                        [0] => Array
                            (
                                [padding_top] => 0
                                [padding_right] => 0
                                [padding_bottom] => 0
                                [padding_left] => 0
                                [background_style] => default
                                [section_width] => default
                                [ID] => 28
                                [key] => field_5876368ea05b4
                                [label] => Section Styles
                                [name] => section_styles
                                [prefix] => acf
                                [type] => section_styles
                                [value] => 
                                [menu_order] => 0
                                [instructions] => 
                                [required] => 0
                                [id] => 
                                [class] => 
                                [conditional_logic] => 0
                                [parent] => 14
                                [wrapper] => Array
                                    (
                                        [width] => 
                                        [class] => 
                                        [id] => 
                                    )

                                [_name] => section_styles
                                [_prepare] => 0
                                [_valid] => 1
                                [parent_layout] => 58763683a05b3
                                [margin_top] => 
                                [margin_right] => 
                                [margin_bottom] => 
                                [margin_left] => 
                                [background_color] => 
                                [background_position_1] => top
                                [background_position_2] => left
                            )

                    )

                [min] => 
                [max] => 
            )

    )

[min] => 
[max] => 
[button_label] => Add Row
[ID] => 14
[key] => field_5873e9fdacab1
[label] => Main Builder
[name] => main_builder
[prefix] => acf
[type] => flexible_content
[value] => Array
    (
        [0] => Array
            (
                [acf_fc_layout] => grid_section
                [section_styles] => Array
                    (
                        [section_width] => default
                        [margin_top] => 
                        [margin_right] => 
                        [margin_bottom] => 
                        [margin_left] => 
                        [padding_top] => 
                        [padding_right] => 
                        [padding_bottom] => 
                        [padding_left] => 
                        [background_color] => 
                        [background_image] => 
                        [background_style] => default
                        [background_position_1] => top
                        [background_position_2] => left
                        [background_position] => top left
                        [padding] => 0 0 0 0
                    )

            )

        [1] => Array
            (
                [acf_fc_layout] => html_section
                [content] => 
                [width] => default-width
                [section_styles] => Array
                    (
                        [section_width] => default
                        [margin_top] => uk-margin-large-top
                        [margin_right] => uk-margin-small-right
                        [margin_bottom] => uk-margin-medium-bottom
                        [margin_left] => 
                        [padding_top] => 
                        [padding_right] => 
                        [padding_bottom] => 
                        [padding_left] => 
                        [background_color] => 
                        [background_image] => 
                        [background_style] => default
                        [background_position_1] => top
                        [background_position_2] => left
                        [background_position] => top left
                        [padding] => 0 0 0 0
                    )

            )

    )

[menu_order] => 0
[instructions] => 
[required] => 0
[id] => 
[class] => 
[conditional_logic] => 0
[parent] => 13
[wrapper] => Array
    (
        [width] => 
        [class] => 
        [id] => 
    )

[_name] => main_builder
[_prepare] => 0
[_valid] => 1
)

0 个答案:

没有答案