Wordpress - adding Featured image to custom Post T

2019-06-25 05:22发布

I'm trying to add a Featured Image to my theme but not for Posts or Pages - I've created a custom type called Properties (its for an estate agent), so how do I enable Featured Image, as it doesn't appear in the sceen options?

Hope someone can help,

$property  = new Cuztom_Post_Type( 'Property', array(
    'supports' => array('title', 'editor')
));

5条回答
仙女界的扛把子
2楼-- · 2019-06-25 05:31

100% working this code

 add_theme_support('post-thumbnails');
add_post_type_support( 'news', 'thumbnail' ); 

function create_posttype() {
    register_post_type( 'news',
        array(
            'labels' => array(
                'name' => __( 'News' ),
                'singular_name' => __( 'news' )
            ),
            'public' => true,
            'has_archive' => true,
            'rewrite' => array('slug' => 'news'),
            'menu_icon' => 'dashicons-format-aside',

        )
    );
}
add_action( 'init', 'create_posttype' );
查看更多
我命由我不由天
3楼-- · 2019-06-25 05:37
$property  = new Cuztom_Post_Type( 'Property', array(
    'supports' => array('title', 'editor', 'thumbnail')
));

I appear to have solved my own question - see above

查看更多
疯言疯语
4楼-- · 2019-06-25 05:42

Probably this would help

    function create_post_type() {
  register_post_type( 'sadaf_films',
    array(
      'labels' => array(
        'name' => __( 'Films' ),
        'singular_name' => __( 'Film' )
      ),
      'public' => true,
      'has_archive' => true,
      'supports' => array( 'title', 'editor', 'custom-fields','thumbnail' ),
    )
  );
}
add_action( 'init', 'create_post_type' );
查看更多
我只想做你的唯一
5楼-- · 2019-06-25 05:47
    add_theme_support('post-thumbnails');
    add_post_type_support( 'testimonial', 'thumbnail' );

    function create_posttype() {
     register_post_type( 'testimonial',
        array(
                'labels' => array(
                    'name' => __( 'Testimonial' ),
                    'singular_name' => __( 'testimonial' )
                ),
                'public' => true,
                'has_archive' => true,
                'rewrite' => array('slug' => 'testimonial'),
                // add category in custom post type
                'taxonomies' => array( 'category'),
            )
        );
    }

    add_action( 'init', 'create_posttype' );
查看更多
迷人小祖宗
6楼-- · 2019-06-25 05:52

This might help someone,

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' );
查看更多
登录 后发表回答