add_post_type_support

函式
add_post_type_support ( $post_type, $feature, $args )
引數
  • (string) $post_type The post type for which to add the feature.
    Required:
  • (string|array) $feature The feature being added, accepts an array of feature strings or a single string.
    Required:
  • (mixed) $args Optional extra arguments to pass along with certain features.
    Required:
定義位置
相關方法
post_type_supportsget_all_post_type_supportsremove_post_type_supportget_post_types_by_supportadd_theme_support
引入
3.0.0
棄用
-

add_post_type_support。一個為文章型別增加特定功能支援的函式。它允許開發者向自定義文章型別新增新的功能,如新增文章縮圖或自定義欄位。

註冊對一個文章型別的某些功能的支援。

所有的核心功能都與編輯螢幕的一個功能區直接相關,如編輯器或元框。功能包括。標題”、”編輯器”、”評論”、”修訂”、”回溯”、”作者”、”摘錄”、”頁面屬性”、”縮圖”、”自定義欄位”和”文章格式”。

此外,”修訂”功能決定了文章型別是否會儲存修訂,而”評論”功能決定了評論數是否會顯示在編輯螢幕上。

第三個可選引數也可以和一個功能一起傳遞,以提供關於支援該功能的額外資訊。

使用例項:

add_post_type_support( ‘my_post_type’, ‘comments’ );
add_post_type_support( ‘my_post_type’, array(
‘author’, ‘excerpt’,
) );
add_post_type_support( ‘my_post_type’, ‘my_feature’, array(
‘field’ => ‘value’,
) );

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function add_post_type_support( $post_type, $feature, ...$args ) {
global $_wp_post_type_features;
$features = (array) $feature;
foreach ( $features as $feature ) {
if ( $args ) {
$_wp_post_type_features[ $post_type ][ $feature ] = $args;
} else {
$_wp_post_type_features[ $post_type ][ $feature ] = true;
}
}
}
function add_post_type_support( $post_type, $feature, ...$args ) { global $_wp_post_type_features; $features = (array) $feature; foreach ( $features as $feature ) { if ( $args ) { $_wp_post_type_features[ $post_type ][ $feature ] = $args; } else { $_wp_post_type_features[ $post_type ][ $feature ] = true; } } }
function add_post_type_support( $post_type, $feature, ...$args ) {
	global $_wp_post_type_features;

	$features = (array) $feature;
	foreach ( $features as $feature ) {
		if ( $args ) {
			$_wp_post_type_features[ $post_type ][ $feature ] = $args;
		} else {
			$_wp_post_type_features[ $post_type ][ $feature ] = true;
		}
	}
}

常見問題

FAQs
檢視更多 >