WordPress函数add_post_type_support() 为自定义文章类型添加支持功能

描述:

注册一个自定义的页面类型

用法:

<?php add_post_type_support( $post_type, $supports ) ?>

参数:

$post_type

(string) (必填) post_type

默认值: None

$supports

(string/array) (必填) 要支持的功能

  • ‘title’标题
  • ‘editor’ 文章内容
  • ‘author’作者信息
  • ‘thumbnail’ 特色图片(前提是主题支持特色图片)
  • ‘excerpt’摘要
  • ‘trackbacks’
  • ‘custom-fields’
  • ‘comments’评论
  • ‘revisions’修订版本
  • ‘page-attributes’(模板和菜单顺序)(层次结构必须为true)(页面模板选择器仅适用于页面发布类型)
  • ‘post-formats’ 文章形式(图像,状态,日志等文章形式)

默认值: None

源文件:

/**
 * Register support of certain features for a post type.
 *
 * All core features are directly associated with a functional area of the edit
 * screen, such as the editor or a meta box. Features include: 'title', 'editor',
 * 'comments', 'revisions', 'trackbacks', 'author', 'excerpt', 'page-attributes',
 * 'thumbnail', 'custom-fields', and 'post-formats'.
 *
 * Additionally, the 'revisions' feature dictates whether the post type will
 * store revisions, and the 'comments' feature dictates whether the comments
 * count will show on the edit screen.
 *
 * @since 3.0.0
 *
 * @global array $_wp_post_type_features
 *
 * @param string       $post_type The post type for which to add the feature.
 * @param string|array $feature   The feature being added, accepts an array of
 *                                feature strings or a single string.
 */
function add_post_type_support( $post_type, $feature ) {
	global $_wp_post_type_features;

	$features = (array) $feature;
	foreach ($features as $feature) {
		if ( func_num_args() == 2 )
			$_wp_post_type_features[$post_type][$feature] = true;
		else
			$_wp_post_type_features[$post_type][$feature] = array_slice( func_get_args(), 2 );
	}
}