Wordpress Attachment Image


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



Copy this code and paste it in your HTML
  1. <?php
  2. $attachments = get_children( array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image') );
  3. foreach ( $attachments as $attachment_id => $attachment ) {
  4. echo '<p>';
  5. echo 'wp_get_attachment_image: ' . wp_get_attachment_image( $attachment_id, array(200,250) ) . '<br />';
  6. echo 'wp_get_attachment_link: ' . wp_get_attachment_link( $attachment_id ) . '<br />';
  7. echo 'wp_get_attachment_url: ' . wp_get_attachment_url( $attachment_id ) . '<br />';
  8. echo 'wp_get_attachment_thumb_url: ' . wp_get_attachment_thumb_url( $attachment_id ) . '<br />';
  9. echo 'get_attachment_link: ' . get_attachment_link( $attachment_id ) . '<br />';
  10. $src = image_get_intermediate_size( $attachment_id, 'medium' );
  11. echo 'image_get_intermediate_size. '; var_dump($src); echo '<br />';
  12. $src = wp_get_attachment_image_src( $attachment_id, 'full', true );
  13. echo 'wp_get_attachment_image_src. '; var_dump($src); echo '<br />';
  14. echo 'Title of attachment: ' . apply_filters( 'the_title', $attachment->post_title ) . '<br />';
  15. echo 'Link to post: ' . get_permalink($image->post_parent) . '<br />';
  16. echo '<hr style="clear:both;" /></p>';
  17. } ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.