I will crawl some data from an XML file and I have all the information I need including the image URL.
There is a function in Wordpress called wp_insert_post which is used to create posts programmically. So far, so good. Simple to use:
http://codex.wordpress.org/Function_Reference/wp_insert_post
What I also need is:
- Add an image attached to the post thumbnail by its image URL (for example http://www.test.com/my-image.jpg)
- Resize it o开发者_JS百科n upload with Wordpress built in functions (for example max 300 x 300, like medium thumbnail settings
You can use this function for that.
media_sideload_image($url,$post_id,$description);
There is a post about this here.
And in the theme you can use this function for getting the thumb in required size
<?php echo get_the_post_thumbnail( $id, $size, $attr ); ?>
Read more at codex
Default thumbnail sizes also can be changed, see this.
精彩评论