Posted By

javifr on 10/29/10


Tagged

wordpress images Attached


Versions (?)

Attached files to single - images


 / Published in: PHP
 

  1. function get_attached_images($number=NULL,$exclude_thumb=TRUE){
  2.  
  3. if($number == NULL ) $number = -1;
  4.  
  5. $thumb_id = get_post_thumbnail_id();
  6.  
  7. global $post;
  8.  
  9. $args = array(
  10. 'post_type' => 'attachment',
  11. 'numberposts' => $number,
  12. 'post_status' => null,
  13. 'post_parent' => $post->ID,
  14. 'orderby' => 'menu_order'
  15. );
  16.  
  17. $attachments = array_reverse(get_posts($args));
  18.  
  19.  
  20. $images = array();
  21.  
  22. if ($attachments) {
  23. foreach ($attachments as $attachment) {
  24. if(!$exclude_thumb){
  25. $image = wp_get_attachment_image_src($attachment->ID,'full',false);
  26. $images[] = array("url" => $image[0], "caption" => $attachment->post_excerpt);
  27. }elseif($thumb_id <> $attachment->ID){
  28. $image = wp_get_attachment_image_src($attachment->ID,'full',false);
  29. $images[] = array("url" => $image[0], "caption" => $attachment->post_excerpt);
  30. }
  31. }
  32. }
  33.  
  34. return $images;
  35. }
  36.  
  37.  
  38.  
  39. // más potente sin exclusión de thumbs
  40.  
  41.  
  42. function get_attached_images($type="thumbnail",$number=NULL){
  43.  
  44. if($number == NULL ) $number = -1;
  45.  
  46. global $post;
  47.  
  48. $args = array(
  49. 'post_type' => 'attachment',
  50. 'numberposts' => $number,
  51. 'post_status' => null,
  52. 'post_parent' => $post->ID,
  53. 'orderby' => 'menu_order'
  54. );
  55.  
  56. $attachments = array_reverse(get_posts($args));
  57.  
  58. $images = array();
  59.  
  60. if ($attachments) {
  61. foreach ($attachments as $attachment) {
  62. $image = wp_get_attachment_image_src($attachment->ID,$type,false);
  63. $image_big = wp_get_attachment_image_src($attachment->ID,"full",false);
  64. $image_medium = wp_get_attachment_image_src($attachment->ID,"medium",false);
  65. $image_large = wp_get_attachment_image_src($attachment->ID,"large",false);
  66. $images[] = array("url" => $image[0], "caption" => $attachment->post_excerpt,"url_big"=> $image_big[0],"url_medium"=>$image_medium[0],"url_large"=>$image_large[0]);
  67. }
  68. }
  69.  
  70. return $images;
  71. }
  72.  

Report this snippet  

You need to login to post a comment.