Wordpress get attachments (not working, but more adaptive than previous)


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



Copy this code and paste it in your HTML
  1. $args = array(
  2. 'post_type' => 'attachment',
  3. 'numberposts' => null,
  4. 'post_status' => null,
  5. 'post_parent' => $post->ID
  6. );
  7.  
  8. $attachments = get_posts( $args );
  9. if ( $attachments ) {
  10. foreach ( $attachments as $attachment ) {
  11.  
  12. $attachment_id = $post->ID ; // attachment ID
  13. $image_attributes = wp_get_attachment_image_src( $attachment_id );
  14. echo $image_attributes[0];
  15. echo $image_attributes[1];
  16. echo $image_attributes[2];
  17.  
  18. echo '<li>';
  19. echo wp_get_attachment_image( $attachment->ID, 'full' );
  20.  
  21. //echo filesize( get_attached_file( $attachment->ID ) );
  22. echo get_post_meta($post->ID, 'wp_attachment_image_alt', true);
  23.  
  24. //echo wp_get_attachment_metadata( $attachment->ID, $unfiltered );
  25.  
  26. //echo wp_get_attachment_link('width');
  27. //echo wp_get_attachment_link('height');
  28.  
  29. //echo '<p>';
  30. //echo apply_filters( 'the_title', $attachment->post_title );
  31. //echo '</p>';
  32. echo '</li>';
  33. }
  34. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.