Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function first_image() {
- global $post;
- if (!has_post_thumbnail($post->ID)) {
- $attached_image = get_children( "post_parent=$post-
- >ID&post_type=attachment&post_mime_type=image&numberposts=1" );
- if ($attached_image) {
- foreach ($attached_image as $attachment_id => $attachment) {
- set_post_thumbnail($post->ID, $attachment_id);
- }
- }
- }
- }
- echo first_image();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement