【问题标题】:Feature thumbnails for specific custom post types特定自定义帖子类型的功能缩略图
【发布时间】:2015-04-10 18:03:02
【问题描述】:

我认为这很简单,但我没有找到任何关于它的内容。我想为我的三种帖子类型提供缩略图,请大家帮助我。

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

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

【问题讨论】:

    标签: wordpress thumbnails custom-post-type


    【解决方案1】:

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

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

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

    【讨论】:

    • 非常感谢!绝对完美!
    【解决方案2】:

    您需要在每个帖子类型中添加一个“支持”行,以便 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') );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-02
      • 1970-01-01
      • 2018-03-10
      • 2021-10-14
      • 2014-04-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多