Wordpress 3 insert image to Custom Post Type item
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
.
精彩评论