Container 是一组自定义字段和显示选项。 容器根据其类型和显示选项显示在后端的不同部分。
默认情况下,所有容器根据它们的类型在所有实体上都是可见的(post_meta
、term_meta
等),并且所有可以访问相关编辑屏幕的用户都可以对其进行编辑。
要创建新容器,您必须指定类型和标题:
use Carbon_Fields\Container;
use Carbon_Fields\Field;
Container::make( 'post_meta', 'Custom Data' )
->where( 'post_type', '=', 'page' )
->add_fields( array(
Field::make( 'map', 'crb_location' )
->set_position( 37.423156, -122.084917, 14 ),
Field::make( 'sidebar', 'crb_custom_sidebar' ),
Field::make( 'image', 'crb_photo' ),
));
要创建一个新的 Container,您只需使用 Container::make( $type, $title )
方法,其中:
Parameter | Description |
---|---|
$type |
Identifier of the container type (accepted values are post_meta , term_meta , user_meta , comment_meta , nav_menu_item and theme_options ). |
$title |
Title of the container. |
或者,您可以使用 Container::make( $type, $id, $title )
为容器传递一个 id,其中:
Parameter | Description |
---|---|
$type |
Identifier of the container type (accepted values are post_meta , term_meta , user_meta , comment_meta , nav_menu_item and theme_options ). |
$id |
Unique id of the container. Automatically prefixed with carbon_fields_container_ |
$title |
Title of the container. |