內容簡介
使用Custom Field Suite構建任意數量的選項屏幕。
例如
首先創建你想在選項屏幕上包含的欄位組(Field Group),確保設置NO Placement Rules。創建後,注意使用的文章ID。然後,像這樣註冊任意數量的選項屏幕:
function my_cfs_options_screens( $screens ) {
$screens[] = array(
'name' => 'options',
'menu_title' => __( 'Site Options' ),
'page_title' => __( 'Customize Site Options' ),
'menu_position' => 100,
'icon' => 'dashicons-admin-generic', // 可選, dashicons-admin-generic是默認值
'field_groups' => array( 'My Field Group' ), // 使用此頁面上CFS Field Group的欄位組名稱(也可以是文章ID)
);
return $screens;
}
add_filter( 'cfs_options_screens', 'my_cfs_options_screens' );
像這樣檢索你的選項:
$value = cfs_get_option( 'options_screen_name', 'cfs_field_name_from_field_group' );
通過在註冊時添加parent參數,您還可以在頂級和/或子級選項頁面中設置多個選項頁面:
function my_cfs_options_screens( $screens ) {
// Parent
$screens[] = array(
'name' => 'options',
'field_groups' => array( 'My Parent Field Group Name' ),
);
// Child
$screens[] = array(
'name' => 'options-nav',
'parent' => 'options', // 父級名稱
'field_groups' => array( 'My Child Field Group Name' ),
);
return $screens;
}
add_filter( 'cfs_options_screens', 'my_cfs_options_screens' );
您還可以使用CFS選項屏幕設置字段組的默認值,從而使字段組同時出現在CFS選項屏幕和文章編輯屏幕上。 CFS選項屏幕將作為默認/後備,文章編輯屏幕將覆蓋這些默認值。
function my_cfs_options_screens( $screens ) {
$screens[] = array(
'name' => 'options',
'menu_title' => __( 'Site Options' ),
'page_title' => __( 'Customize Site Options' ),
'menu_position' => 100,
'icon' => 'dashicons-admin-generic', // 可選, dashicons-admin-generic是默認值
'field_groups' => array(
array(
'title' => 'My CFS Field Group Name',
'has_overrides' => true,
),
),
);
return $screens;
}
add_filter( 'cfs_options_screens', 'my_cfs_options_screens' );
請檢查cfs_options_screens_override_note_default和cfs_options_screens_override_note_override過濾器以自定義消息,以覆蓋CFS選項屏幕的默認值。
外掛標籤
開發者團隊
原文外掛簡介
Build any number of options screens based on Custom Field Suite.
For Example
Begin by creating Field Group(s) you want to include on your options screen. Be sure to set NO Placement Rules. Once it’s created, note the post ID it uses. You can then register any number of options screens like so:
function my_cfs_options_screens( $screens ) {
$screens[] = array(
'name' => 'options',
'menu_title' => __( 'Site Options' ),
'page_title' => __( 'Customize Site Options' ),
'menu_position' => 100,
'icon' => 'dashicons-admin-generic', // optional, dashicons-admin-generic is the default
'field_groups' => array( 'My Field Group' ), // Field Group name(s) of CFS Field Group to use on this page (can also be post IDs)
);
return $screens;
}
add_filter( 'cfs_options_screens', 'my_cfs_options_screens' );
Retrieve your options like so:
$value = cfs_get_option( 'options_screen_name', 'cfs_field_name_from_field_group' );
You can set up multiple top level and/or children options pages by adding a parent argument when registering your screen:
function my_cfs_options_screens( $screens ) {
// Parent
$screens[] = array(
'name' => 'options',
'field_groups' => array( 'My Parent Field Group Name' ),
);
// Child
$screens[] = array(
'name' => 'options-nav',
'parent' => 'options', // name of the parent
'field_groups' => array( 'My Child Field Group Name' ),
);
return $screens;
}
add_filter( 'cfs_options_screens', 'my_cfs_options_screens' );
You can also use CFS Options Screens to set up Field Group ‘defaults’, allowing a Field Group to appear both on a CFS Options Screen and a post edit screen. The CFS Options Screen will act as the default/fallback and the post edit screen will override those defaults.
function my_cfs_options_screens( $screens ) {
$screens[] = array(
'name' => 'options',
'menu_title' => __( 'Site Options' ),
'page_title' => __( 'Customize Site Options' ),
'menu_position' => 100,
'icon' => 'dashicons-admin-generic', // optional, dashicons-admin-generic is the default
'field_groups' => array(
array(
'title' => 'My CFS Field Group Name',
'has_overrides' => true,
),
),
);
return $screens;
}
add_filter( 'cfs_options_screens', 'my_cfs_options_screens' );
Check out the cfs_options_screens_override_note_default and cfs_options_screens_override_note_override filters to customize the messaging for CFS Options Screens overrides.
