0

Is it possible to get the raw info from a post gallery and display on the page, specifically for a slider?

So can you create a gallery then display the gallery on a page with the full size image, as well as the image caption and alt text?

So for each image...

<div>
<img src='image source' title='image title' />
<figure>image caption, image alt tag</figure>
</div>

Basically strip everything out apart from the full size image, alt and caption text?

Is this possible?

Thank you for any help.

1
  • that would be more <figure><img src='image source' title='image title' /><figcaption>image caption, image alt tag</figcaption></figure>.
    – JMau
    Commented Aug 28, 2013 at 9:41

1 Answer 1

0

A gallery is at heart just the set of attached posts, so...

$post_id = 1; // set to your desired parent post
$attachments = new WP_Query( 
  array(
    'post_parent' => $post_id, // post to which the gallery is attached
    'post_status' => 'inherit', 
    'post_type' => 'attachment', 
    'post_mime_type' => 'image', 
//  'order' => $order, 
//  'orderby' => $orderby
  ) 
);
// var_dump($attachments); // debug

foreach ($attachments->posts as $p) {
  var_dump($p);
  var_dump(wp_get_attachment_image_src($p->ID));
  var_dump(get_post_custom($p->ID));
}

You should be able to find all you need, and a lot more, in that dumped data. In fact, I think that all you need is in the last two of those dumps so you can probably simplify to this:

$post_id = 1; // set to your desired parent post
$attachments = new WP_Query( 
  array(
    'fields' => 'ids',
    'post_parent' => $post_id, // post to which the gallery is attached
    'post_status' => 'inherit', 
    'post_type' => 'attachment', 
    'post_mime_type' => 'image', 
//  'order' => $order, 
//  'orderby' => $orderby
  ) 
);
// var_dump($attachments); 

foreach ($attachments->posts as $ids) {
  var_dump(wp_get_attachment_image_src($ids));
  var_dump(get_post_custom($ids));
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.