Australia's Leading Digital Marketing Experts. T. 1300 235 433  |  Aggregation Enquires Welcome

Example Interest Rates: Home Loan Variable: 1.89% (1.9%*) • Home Loan Fixed: 1.84% (2.11%*) • Fixed: 1.84% (2.11%*) • Variable: 1.89% (1.9%*) • Investment IO: 2.05% (4.36%*) • Investment PI: 1.58% (2.72%*)

Return all Images (Except the Featured Image) Attached to a WordPress Post or Page

This function supports a number of our image gallery functions. The first is published on this page. There's also an article on our blog, "Find all Images (Except the Featured Image) Attached to a WordPress Post or Page", that discuses the WordPress functions in a little more depth.

Copy and paste the WordPress function into your theme's functions.php file or, if you sensibly have one installed, your custom functions plugin.

1
<?php 
2
/*
3
 Return all Images (Except the Featured Image) Attached to a WordPress Post or Page
4
 http://www.beliefmedia.com/wordpress-post-images
5
*/
6
 
7
8
 
9
  $attachments = get_posts( array(
10
    'post_type' => 'attachment',
11
    'posts_per_page' => -1,
12
    'post_status' => 'any',
13
    'post_parent' => $id,
14
    'exclude' => get_post_thumbnail_id())
15
  );
16
 
17
  /* Return array of all images */
18
  if ($attachments) {
19
    $i = 0; foreach ($attachments as $attachment) {
20
      $imagesrc = wp_get_attachment_image_src($attachment->ID, $size = 'medium');
21
      $imagesrc_medium_large = wp_get_attachment_image_src($attachment->ID, $size = 'medium_large');
22
      $imagesrc_full = wp_get_attachment_image_src($attachment->ID, $size = 'full');
23
      $imagesrc_thumbnail = wp_get_attachment_image_src($attachment->ID, $size = 'thumbnail');
24
 
25
      $images["$i"]['src'] = $imagesrc['0'];
26
      $images["$i"]['medium_large'] = $imagesrc_medium_large['0'];
27
      $images["$i"]['full'] = $imagesrc_full['0'];
28
      $images["$i"]['thumbnail'] = $imagesrc_thumbnail['0'];
29
      $images["$i"]['title'] = get_the_title($attachment->ID);
30
      $images["$i"]['caption'] = $attachment->post_excerpt;
31
      $i++;
32
    }
33
  }
34
 
35
 return $images;
36
}

Download our 650-page guide on Finance Marketing. We'll show you exactly how we generate Billions in volume for our clients.

  AUS Eastern Standard Time (Connecticut)

  Want to have a chat?
 

Like this article?

Share on facebook
Share on Facebook
Share on twitter
Share on Twitter
Share on linkedin
Share on Linkdin
Share on pinterest
Share on Pinterest

Leave a comment