为什么“自定义帖子类型”中不显示“精选图片”?


31

我在我的functions.php中添加了缩略图支持,并添加了以下内容

// Add Thumbnail Support
add_theme_support('post-thumbnails');
set_post_thumbnail_size( 140, 140, true );

我用创建自定义帖子类型

// Create Custom Post Type for Work
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'custom_post',
    array(
        'thumbnail',
        'labels' => array(
            'name' => __( 'Custom' ),
            'singular_name' => __( 'Custom' )
        ),
        'public' => true,
        'has_archive' => true,
        'rewrite' => array('slug' => 'custom'),
        'taxonomies' => array('category', 'post_tag')
    )
  );
}

但是,当我在“自定义帖子类型”中创建新帖子时,“特色图片”元框不会显示。我也曾在声明自定义帖子类型时尝试使用数组,如下所示,但这也不起作用

// Add Thumbnail Support
add_theme_support('post-thumbnails', array ('post','work','custom_post'));
set_post_thumbnail_size( 140, 140, true );

我想念什么?

Answers:


53

尝试参数:register_post_type supports

'supports' => array( 'thumbnail' )

当然可以。我盯着它看了太久,或者我还没有喝咖啡。谢谢米洛!
瑞安

4
这也删除了对标题和编辑器内容的支持,默认情况下启用这些功能。我不得不用'supports' => array('title', 'editor', 'thumbnail'),
变形虫虫

1
另外,切记实际上要为您的主题允许这样的缩略图:add_theme_support( 'post-thumbnails' );
skolind

7

将此参数添加到您的数组中:

'supports' => array('thumbnail'),

编辑:米洛更快。


我认为这比milo的更适合我的需求:D
Martijn van Hoof

4

试试这个对我有用.....

add_theme_support('post-thumbnails');
add_post_type_support( 'my_product', 'thumbnail' );    
function create_post_type() {
        register_post_type( 'my_product',
            array(
                'labels' => array(
                    'name' => __( 'Products' ),
                    'singular_name' => __( 'Product' )
                ),
                'public' => true,
                'has_archive' => true
            )
        );
    }
    add_action( 'init', 'create_post_type' );
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.