3

我为主题选项创建容器并向其中添加字段数组。然后打开此选项页面,查看应添加字段的标题和空块。如何显示字段?

碳场 2.1.0

use Carbon_Fields\Container;
use Carbon_Fields\Field;
Container::make( 'theme_options', __( 'Theme Options', 'crb' ) )
  ->add_fields( array(
      Field::make( 'text', 'crb_text', 'Text Field' ),
  ) );

在此处输入图像描述

4

2 回答 2

4

为了让 Carbon Fields 在插件中工作,我必须定义Carbon_Fields\URL修复它的值。

我的插件根文件中的引导代码如下所示:

// Define the url where Carbon Fields assets will be enqueued from
define( 'Carbon_Fields\URL', trailingslashit( plugin_dir_url( __FILE__ ) ) . 'vendor/htmlburger/carbon-fields/' );

// Boot Carbon Fields
\Carbon_Fields\Carbon_Fields::boot();

// Return the class that sets up the settings pages
return new \MyPlugin\Settings();

您可以在此处查看在引导之前可以覆盖的所有碳字段常量:https ://github.com/htmlburger/carbon-fields/blob/development/config.php

于 2020-08-07T13:12:50.357 回答
0

您可以在 functions.php 上添加代码并在下面使用此代码,

use Carbon_Fields\Field;
use Carbon_Fields\Container;

add_action( 'carbon_fields_register_fields', 'crb_attach_theme_options' );
function crb_attach_theme_options() {
    Container::make( 'theme_options', __( 'Theme Options', 'crb' ) )
        ->add_fields( array(
            Field::make( 'rich_text', 'crb_footer_copyright', 'Copyright' ),
        ) );
}

于 2018-11-03T07:07:39.043 回答