Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. <?php
  2. function first_image() {
  3. global $post;
  4.  
  5. if (!has_post_thumbnail($post->ID)) {
  6. $attached_image = get_children( "post_parent=$post-
  7. >ID&post_type=attachment&post_mime_type=image&numberposts=1" );
  8.  
  9. if ($attached_image) {
  10. foreach ($attached_image as $attachment_id => $attachment) {
  11. set_post_thumbnail($post->ID, $attachment_id);
  12. }
  13. }
  14. }
  15. }
  16.  
  17. echo first_image();
  18. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement