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

时间:2015-02-10 16:03:12

标签: wordpress thumbnails custom-post-type

我认为它非常简单,但我找不到任何关于它的东西..我想为我的三种帖子类型添加缩略图,我请你们帮助我。

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')
    )
);
}

我认为没有更多的说法,对你们来说这可能非常简单....

2 个答案:

答案 0 :(得分:0)

您需要定义对要素图像的支持,因此在每个数组之后为所有自定义帖子类型添加以下行。

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

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

答案 1 :(得分:0)

你需要添加一个'支持'每个帖子类型中的行,以便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') );
相关问题