我正在尝试为自定义帖子类型添加特色图像
我在主题的functions.php文件中添加了主题支持。以下是代码:
function custom_theme_setup() {
add_theme_support( 'post-formats',array('link','gallery'));
add_theme_support( 'post-thumbnails');
add_theme_support( 'custom-background');
add_theme_support( 'custom-header');
add_theme_support( 'custom-logo');
add_theme_support( 'automatic-feed-links');
// add_theme_support( 'html5');
add_theme_support( 'title-tag');
}
add_action( 'init', 'custom_theme_setup');
我还尝试将support子句添加到register-post类型部分,但仍然没有。
这是注册自定义邮政类型代码:
function movies_create_post_type() {
register_post_type( 'movies',
array(
'labels' => array(
'name' => __( 'Movies' ),
'singular_name' => __( 'Movie' ),
'supports' => array( 'title', 'editor', 'comments', 'excerpt', 'custom-fields', 'thumbnail' ),
),
'public' => true,
'has_archive' => true,
'menu_icon' => 'dashicons-format-video',
'show_ui' => true,
)
);
}
add_action('init','movies_create_post_type');
我到处找了,但找不到解决这个问题的合适办法。
注意:我可以为我的正常帖子设置特色图片,问题是自定义帖子类型。此外,我还通过我自己编码的插件。
提前谢谢。
尝试将支持数组放在两个索引之外,就像一样的public has_archive menu_icon show_ui
function movies_create_post_type() {
register_post_type( 'movies',
array(
'labels' => array(
'name' => __( 'Movies' ),
'singular_name' => __( 'Movie' )
),
'public' => true,
'supports' => array( 'title', 'editor', 'comments', 'excerpt', 'custom-fields', 'thumbnail' ),
'has_archive' => true,
'menu_icon' => 'dashicons-format-video',
'show_ui' => true,
)
);
}
希望它能有所帮助!
在标签数组中不传递支持参数
'supports' => array( 'title', 'editor', 'comments', 'excerpt', 'custom-fields', 'thumbnail' ),
请检查以下代码
function movies_create_post_type() {
register_post_type( 'movies',
array(
'labels' => array(
'name' => __( 'Movies' ),
'singular_name' => __( 'Movie' )
),
'public' => true,
'supports' => array( 'title', 'editor', 'comments', 'excerpt', 'custom-fields', 'thumbnail' ),
'has_archive' => true,
'menu_icon' => 'dashicons-format-video',
'show_ui' => true,
)
);
}
有关更多信息,请检查register_post_type