WordPress開發(fā)函數(shù)add_post_type_support()
WordPress開發(fā)函數(shù)add_post_type_support(),注冊對某個post類型的某些特性的支持。
用法:
add_post_type_support( string $post_type, string|array $feature, mixed $args )
描述
所有的核心功能都與編輯屏幕的功能區(qū)域直接相關(guān),比如編輯器或元框。功能包括:“標(biāo)題”,“編輯器”,“評論”,“修訂”,“trackbacks”,“作者”,“摘錄”,“頁面屬性”,“縮略圖”,“自定義字段”和“post-formats”。
此外,' revisions '特性規(guī)定了post類型是否會存儲修訂,而' comments '特性則規(guī)定了評論計數(shù)是否會顯示在編輯屏幕上。
第三個可選參數(shù)也可以隨特性一起傳遞,以提供有關(guān)支持該特性的附加信息。
使用示例:
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',
) );
參數(shù):
$post_type
(string) (必需) 要為其添加特性的帖子類型。
$feature
(string|array) (必需) 添加的特性接受特性字符串?dāng)?shù)組或單個字符串。
$args
(mixed) (可選) 與某些特性一起傳遞的額外參數(shù)。
更多信息
這個函數(shù)應(yīng)該使用init action鉤子來調(diào)用,就像上面的例子一樣。
多點
要在多站點安裝中顯示“特色圖片”元框,請確保您更新了允許上傳的文件類型,在網(wǎng)絡(luò)管理,網(wǎng)絡(luò)管理設(shè)置子面板#Upload_Settings,媒體上傳按鈕選項。默認是關(guān)閉的。
來源:
文件: wp-includes/post.php
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;
}
}
}
更新日志:

用戶貢獻的筆記
(由Hay貢獻- 11個月前)
關(guān)于所有可能特性的概述(例如' title ', ' editor '等),請參閱post_type_supports文檔。
(由Marc Heatley在4年前貢獻)
不幸的是,
add_post_type_support('page', 'thumbnail');
不會添加特色圖片到頁面。為此,你需要[添加后縮略圖的主題支持
add_theme_support('post-thumbnails', array('post', 'page'));
(由Codex - 6年前貢獻)
這個例子增加了對頁面摘錄的支持(假設(shè)它*不*顯示在“屏幕選項”下):
add_action('init', 'wpdocs_custom_init');
/**
* Add excerpt support to pages
*/
function wpdocs_custom_init() {
add_post_type_support( 'page', 'excerpt' );
}
?>