Query_posts and attachments

I need some guidance on some WP code. I’m wondering if it’s possible to take this code (which is grabbing all the images from the posts across my site and dumping them out):

$args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => null ); 
$attachments = get_posts( $args );
if ($attachments) {
foreach ( $attachments as $post ) {
setup_postdata($post);
the_attachment_link($post->ID, true);
the_excerpt();
}
}

and use the query_posts(); function in WP instead so I could create some pagination for all the images.

Read More

I seem to have got something working with this below, but it’s pulling in one post, infinitely.

<?php
$args = array( 'post_type' => 'attachment', 'post_status' => null, 'post_parent' => null, );
$attachments = get_posts( $args );
if ($attachments) {
    foreach ( $attachments as $post ) {
        setup_postdata($post);
        the_attachment_link($post->ID, true);
        the_excerpt();
    }
}
?>

<?php endwhile; ?>

You can see what I’ve got so far here: http://itsfoolsgold.com/grid/

Thanks so much in advance,
R

Related posts

Leave a Reply