wordpress redux框架 - 创建一个转发器字段并稍后显示值

时间:2017-05-05 03:04:20

标签: php wordpress redux-framework

我试图在wordpress主题中使用Redux而不是插件。在$loop = 0; foreach($_FILES['file']['name'] as $file){ $filename = $file['name'][$loop]; $filetmp = $file['tmp_name'][$loop]; $file_ext = explode('.',$filename); $file_ext = strtolower(end($file_ext)); $file_name_new = uniqid('',true) .'.'. $file_ext; $file_destination = 'file/' .$file_name_new; move_uploaded_file($filetmp, $file_destination); $loop++; } 中,我同时包含了functions.phpredux-framework.php

现在我需要创建一个转发器字段。

Redux doc开始,我使用以下代码来创建转发器字段:

sample-config.php

但如果我将代码放在$this->sections[] = array( 'title' => __('Repeater Field', 'redux-framework-demo' ), 'icon' => 'el-icon-thumbs-up', 'fields' => array( array( 'id' => 'repeater-field-id', 'type' => 'repeater', 'title' => __( 'Title', 'redux-framework-demo' ), 'subtitle' => __( '', 'redux-framework-demo' ), 'desc' => __( '', 'redux-framework-demo' ), //'group_values' => true, // Group all fields below within the repeater ID //'item_name' => '', // Add a repeater block name to the Add and Delete buttons //'bind_title' => '', // Bind the repeater block title to this field ID //'static' => 2, // Set the number of repeater blocks to be output //'limit' => 2, // Limit the number of repeater blocks a user can create //'sortable' => false, // Allow the users to sort the repeater blocks or not 'fields' => array( array( 'id' => 'title_field', 'type' => 'text', 'placeholder' => __( 'Title', 'redux-framework-demo' ), ), array( 'id' => 'text_field', 'type' => 'text', 'placeholder' => __( 'Text Field', 'redux-framework-demo' ), ), array( 'id' => 'select_field', 'type' => 'select', 'title' => __( 'Select Field', 'redux-framework-demo' ), 'options' => array( '1' => __( 'Option 1', 'redux-framework-demo' ), '2' => __( 'Option 2', 'redux-framework-demo' ), '3' => __( 'Option 3', 'redux-framework-demo' ), ), 'placeholder' => __( 'Listing Field', 'redux-framework-demo' ), ), ) ) ) ); 中,那么functions.php变量会引用什么?它会产生错误。那么如何使用代码片段以便我也可以从模板文件中检索值?

1 个答案:

答案 0 :(得分:0)

您必须尝试使用​​旧版本系统来创建一个部分。您可以尝试新版本系统,我不确定这是否有效,但您可以尝试这种方式:

Redux::setSection($opt_name, array(
    'title'             => __('Ads Sections', 'cbnews'),
    'id'                => 'ads-sections',
    'desc'              => __('You can manage your ads', 'cbnews'),
    'icon'              => 'dashicons dashicons-dashboard',
    'fields'            => array(
        array(
            'id'         => 'repeater-field-id',
            'type'       => 'repeater',
            'title'      => __( 'Title', 'redux-framework-demo' ),
            'subtitle'   => __( '', 'redux-framework-demo' ),
            'desc'       => __( '', 'redux-framework-demo' ),
            //'group_values' => true, // Group all fields below within the repeater ID
            //'item_name' => '', // Add a repeater block name to the Add and Delete buttons
            //'bind_title' => '', // Bind the repeater block title to this field ID
            //'static'     => 2, // Set the number of repeater blocks to be output
            //'limit' => 2, // Limit the number of repeater blocks a user can create
            //'sortable' => false, // Allow the users to sort the repeater blocks or not
            'fields'     => array(
                array(
                    'id'          => 'title_field',
                    'type'        => 'text',
                    'placeholder' => __( 'Title', 'redux-framework-demo' ),
                ),
                array(
                    'id'          => 'text_field',
                    'type'        => 'text',
                    'placeholder' => __( 'Text Field', 'redux-framework-demo' ),
                ),
                array(
                    'id'          => 'select_field',
                    'type'        => 'select',
                    'title' => __( 'Select Field', 'redux-framework-demo' ),
                    'options'     => array(
                        '1'             => __( 'Option 1', 'redux-framework-demo' ),
                        '2'             => __( 'Option 2', 'redux-framework-demo' ),
                        '3'             => __( 'Option 3', 'redux-framework-demo' ),
                    ),
                    'placeholder' => __( 'Listing Field', 'redux-framework-demo' ),
                ),
            )
        )
    )
));