How to get attachments of parent page only with query_posts?

Basically I am trying to get the gallery of parent page, and I’ve been playing with query_posts to do that, the following code seems to be getting me closer to what I need but it is actually getting the attachments from other places rather than only parent page of current page, any one?:

<?php
 $args = array('post_type' => 'attachment',
  'numberposts' => -1,
  'post_status' => null,
  'post_parent' => 0,
  'order_by' => 'menu_order',
  'order' => 'ASC');
 $attachments = get_posts($args);
 if($attachments)
 {
  echo '<ul class="imagelist">';
  foreach($attachments as $attachment)
 {
 echo '<li>';
$large = wp_get_attachment_image_src($attachment->ID, 'large');
$thumb = wp_get_attachment_image($attachment->ID, 'thumbnail');
echo '<a href="'. $large[0] .'">' . $thumb . '</a>';
echo '</li>';
 }
 echo '</ul>';
}
?>

Related posts

Leave a Reply

1 comment

  1. You should have set post_parent to the current post parent ID:

    global $post;
    $args = array(
        'post_type' => 'attachment',
        'numberposts' => -1,
        'post_status' => null,
        'post_parent' => $post->post_parent,
        'order_by' => 'menu_order',
        'order' => 'ASC'
    );