Wordpress - adding Featured image to custom Post T

2019-06-25 05:35发布

问题:

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

回答1:

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

I appear to have solved my own question - see above



回答2:

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


回答3:

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


回答4:

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


回答5:

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