I'm having some trouble with this sample widget code. I want to get all images (Minus the post thumbnail) from a page called "Gallery" but for some reason this is pulling all uploaded images from the entire site.
Also, how would I go about excluding the post thumbnail from this query?
query_posts('pagename=gallery');
if (have_posts()) :
echo "<ul class='recentwidget group photowidget'>";
while (have_posts()) : the_post();
$args = array(
'post_type' => 'attachment',
'numberposts' => 1,
'post_status' => null,
'post_parent' => $post->ID
);
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
echo '<li class="left imageshadow photolarge">';
echo wp_get_attachment_image( $attachment->ID, 'full' );
echo '</li>';
}
}
endwhile;
endif;
wp_reset_query();
query_posts
is not without drawbacks. Have you tried usingget_posts
instead? But then, I think using The Loop at all in this case is overkill. Just hardcode the page ID into your call toget_posts
(which is currently inside The Loop). – Raphael Jan 17 '12 at 20:14