WordPress开发函数add_post_type_support(),注册对某个post类型的某些特性的支持。

用法:

add_post_type_support( string $post_type, string|array $feature, mixed $args )

描述

所有的核心功能都与编辑屏幕的功能区域直接相关,比如编辑器或元框。功能包括:“标题”,“编辑器”,“评论”,“修订”,“trackbacks”,“作者”,“摘录”,“页面属性”,“缩略图”,“自定义字段”和“post-formats”。

此外,' revisions '特性规定了post类型是否会存储修订,而' comments '特性则规定了评论计数是否会显示在编辑屏幕上。

第三个可选参数也可以随特性一起传递,以提供有关支持该特性的附加信息。

使用示例:

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',

) );

参数:

$post_type

(string) (必需) 要为其添加特性的帖子类型。

$feature

(string|array) (必需) 添加的特性接受特性字符串数组或单个字符串。

$args

(mixed) (可选) 与某些特性一起传递的额外参数。

更多信息

这个函数应该使用init action钩子来调用,就像上面的例子一样。

多点

要在多站点安装中显示“特色图片”元框,请确保您更新了允许上传的文件类型,在网络管理,网络管理设置子面板#Upload_Settings,媒体上传按钮选项。默认是关闭的。

来源:

文件: 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;

}

}

}

更新日志:
WordPress开发函数add_post_type_support() (https://www.wpzt.net/) WordPress开发教程 第1张
用户贡献的笔记

(由Hay贡献- 11个月前)

关于所有可能特性的概述(例如' title ', ' editor '等),请参阅post_type_supports文档。

(由Marc Heatley在4年前贡献)

不幸的是,

add_post_type_support('page', 'thumbnail');

不会添加特色图片到页面。为此,你需要[添加后缩略图的主题支持

add_theme_support('post-thumbnails', array('post', 'page'));

add_theme_support()

(由Codex - 6年前贡献)

这个例子增加了对页面摘录的支持(假设它*不*显示在“屏幕选项”下):

add_action('init', 'wpdocs_custom_init');

/**

* Add excerpt support to pages

*/

function wpdocs_custom_init() {

add_post_type_support( 'page', 'excerpt' );

}

?>