The WordPress codex on wp_get_attachment_link says you can use the $permalink parameter to link to the page, not the image. But I would like to link to the post instead. I'm trying to get a list of images using the following (updated, see answers below):
<?php $new_query = new WP_Query('&showposts=1'); ?>
<?php while ($new_query->have_posts()) : $new_query->the_post(); ?>
<?php $args = array (
'post_type' => 'attachment',
'numberposts' => 18,
'orderby' => 'date',
'status' => 'publish',
'post_mime_type' => 'image',
'parent' => $post->ID
); ?>
<?php $attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $attachment) {
echo '<li>';
echo '<a href=" ' . get_permalink( $post->ID ) . '">';
echo wp_get_attachment_image($attachment->ID, 'thumbnail' );
echo '</a></li>';
}
};
endwhile;
?>
Having trouble getting the images to link to the post. I'm not sure how to filter this to get the post, not the page.