2017-05-05 24 views
0

我想在WordPress主題內使用Redux,而不是作爲插件。在functions.php我包括redux-framework.phpsample-config.phpWordPress的REDX框架 - 創建一箇中繼器字段,並稍後顯示值

現在我需要創建一箇中繼器字段。

Redux doc,我得到了下面的代碼,以創建一箇中繼器領域使用方法:

$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的代碼,會出現什麼$this變量是指什麼?它會產生錯誤。那麼如何使用代碼片段,以便我可以從模板文件中檢索值?

回答

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'), 
       ), 
      ) 
     ) 
    ) 
)); 
相關問題