Get Post Thumbnail


/ Published in: PHP
Save to your folder(s)

For Wordpress. Used to get the url of the post Thumbnail.


Copy this code and paste it in your HTML
  1. <?php
  2. //Get images attached to the post
  3. $args = array(
  4. 'post_type' => 'attachment',
  5. 'post_mime_type' => 'image',
  6. 'numberposts' => -1,
  7. 'order' => 'ASC',
  8. 'post_status' => null,
  9. 'post_parent' => $post->ID
  10. );
  11. $attachments = get_posts($args);
  12. if ($attachments) {
  13. foreach ($attachments as $attachment) {
  14. $img = wp_get_attachment_thumb_url( $attachment->ID );
  15. break;
  16. }
  17. //Display image
  18. }
  19. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.