Show WordPress Post Attachments


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

taken from wordpress-- it took me a whole to find this on their site


Copy this code and paste it in your HTML
  1. // place inside loop
  2. $args = array(
  3. 'post_type' => 'attachment',
  4. 'numberposts' => null,
  5. 'post_status' => null,
  6. 'post_parent' => $post->ID
  7. );
  8. $attachments = get_posts($args);
  9. if ($attachments) {
  10. foreach ($attachments as $attachment) {
  11. echo apply_filters('the_title', $attachment->post_title);
  12. the_attachment_link($attachment->ID, false);
  13. }
  14. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.