特定自定义 post 类型的功能缩略图

Feature thumbnails for specific custom post types

我认为它很简单,但我没有找到任何相关信息..我想为我的三种 post 类型添加缩略图,请大家帮助我。

add_theme_support( 'post-thumbnails', array( 'crew', 'staff' , 'guest') );

add_action( 'init', 'create_post_type' );

function create_post_type() {
register_post_type( 'crew',
    array(
        'labels' => array(
        'name' => __( 'Crew' ),
        'singular_name' => __( 'Crew' )),
        'public' => true,
        'has_archive' => true,
        'rewrite' => array('slug' => 'crew')
    )
);

register_post_type( 'staff',
    array(
        'labels' => array(
        'name' => __( 'Staff' ),
        'singular_name' => __( 'Staff' )),
        'public' => true,
        'has_archive' => true,
        'rewrite' => array('slug' => 'staff')
    )
);

register_post_type( 'guest',
    array(
        'labels' => array(
        'name' => __( 'Gast' ),
        'singular_name' => __( 'Gast' )),
        'public' => true,
        'has_archive' => true,
        'rewrite' => array('slug' => 'guest')
    )
);
}

我觉得没什么好说的,对你们来说可能很简单....

您需要定义对特征图像的支持,因此在所有自定义 post 类型的每个数组后添加以下行。

'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'sticky')

您当然可以删除或添加您需要或不需要的功能。查看法典中的所有支持:http://codex.wordpress.org/Function_Reference/register_post_type#Arguments

您需要在每个 post 类型中添加一个 'supports' 行,以便 WP 知道每个类型允许哪些功能。

使用您的示例,它应该看起来像这样以支持特色图片:

add_action( 'init', 'create_post_type' );

function create_post_type() {
register_post_type( 'crew',
    array(
        'labels' => array(
        'name' => __( 'Crew' ),
        'singular_name' => __( 'Crew' )),
        'public' => true,
        'has_archive' => true,
        'rewrite' => array('slug' => 'crew')
    ),
    'supports' => array( 'title', 'editor', 'excerpt', 'custom-fields', 'thumbnail' )
);

register_post_type( 'staff',
    array(
        'labels' => array(
        'name' => __( 'Staff' ),
        'singular_name' => __( 'Staff' )),
        'public' => true,
        'has_archive' => true,
        'rewrite' => array('slug' => 'staff')
    ),
    'supports' => array( 'title', 'editor', 'excerpt', 'custom-fields', 'thumbnail' )
);

register_post_type( 'guest',
    array(
        'labels' => array(
        'name' => __( 'Gast' ),
        'singular_name' => __( 'Gast' )),
        'public' => true,
        'has_archive' => true,
        'rewrite' => array('slug' => 'guest')
    ),
    'supports' => array( 'title', 'editor', 'excerpt', 'custom-fields', 'thumbnail' )
);
}

删除这一行:

add_theme_support( 'post-thumbnails', array( 'crew', 'staff' , 'guest') );