Answers:
默认情况下,所有自定义帖子都会添加对“标题”和“编辑器”的支持,如果您需要更多内容,例如注释,缩略图和修订,则必须在support参数中手动添加。
在此处阅读有关如何注册自定义帖子类型的更多信息,还可以找到有关支持的部分以了解可以添加的内容。
这是一个为自定义帖子“ Books”注册缩略图的示例,它支持以下内容: 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments'
function codex_custom_init() {
$labels = array(
'name' => _x('Books', 'post type general name'),
'singular_name' => _x('Book', 'post type singular name'),
'add_new' => _x('Add New', 'book'),
'add_new_item' => __('Add New Book'),
'edit_item' => __('Edit Book'),
'new_item' => __('New Book'),
'all_items' => __('All Books'),
'view_item' => __('View Book'),
'search_items' => __('Search Books'),
'not_found' => __('No books found'),
'not_found_in_trash' => __('No books found in Trash'),
'parent_item_colon' => '',
'menu_name' => __('Books')
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
);
register_post_type('book',$args);
}
add_action( 'init', 'codex_custom_init' );
对于自定义帖子,首先必须启用对缩略图的支持:
add_theme_support( 'post-thumbnails' );
function theme_setup() {
register_post_type( 'yourposttype', array(
...,
'supports' => array('title', ...,'thumbnail'),
));
}
add_action( 'after_setup_theme', 'theme_setup' );