开发者

Wordpress 3 insert image to Custom Post Type item

开发者 https://www.devze.com 2023-01-02 08:32 出处:网络
I have a Custom Post Type and I am going to customize it to show a list of some products with 开发者_如何学编程images. I have all text fields working fine but I need also an image to be attached to ea

I have a Custom Post Type and I am going to customize it to show a list of some products with 开发者_如何学编程images. I have all text fields working fine but I need also an image to be attached to each item. How can I do this?


If each post is a single item, you can add post thumbnail support in your theme, which allows users to either browse for or upload an image and assign it to the post.

add_theme_support('post-thumbnails')

You'll also need to add thumbnail to your supports array when you register your custom post type.

register_post_type('product', array(
    'supports' => array('title', 'content', 'thumbnail')
))

You can then retrieve the thumbnail in your theme files using get_post_thumbnail(). Check out the other post thumbnail functions in wp-includes/post-thumbnail-template.php.

0

精彩评论

暂无评论...
验证码 换一张
取 消