Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

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

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.