Yeah, basically I want to be able to show 15 images attached to a certain page and have pagination when the page has more than 15 images.

I'm not very well versed on this kind of query so I'm a bit stumped.

 <?php $args = array('numberposts' => 15, 'orderby' => 'menu_order', 'order' => 'ASC', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'post_parent' => $post->ID); ?>

                    <?php if ( $photos = get_posts($args) ) : ?>

                        <?php foreach ( $photos as $photo ) : ?>

                            <a href="<?php echo $photo->guid; ?>" target="_blank" class="lightbox" rel="[<?php echo $post->ID; ?>]"><?php echo wp_get_attachment_image($photo->ID,'thumbnail'); ?></a>

                        <?php endforeach; ?>

                    <?php endif; ?>
link|improve this question

feedback

1 Answer

Yup. You'll need to get/set $paged with your query, like so:

<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
  'numberposts' => 15, 
  'orderby' => 'menu_order', 
  'order' => 'ASC', 
  'post_type' => 'attachment', 
  'post_mime_type' => 'image', 
  'post_parent' => $post->ID, 
  'paged' => $paged
  ); ?>

                <?php $photos = new WP_Query($args);  ?>
                    <?php if ( $photos->have_posts() ) :  ?>
                      <?php while ( $photos->have_posts() ) : $photos->the_post(); ?>
                        <?php $url = wp_get_attachment_image_src($post->ID); ?>
                        <a href="<?php echo $url[0]; ?>" target="_blank" class="lightbox" rel="[<?php echo $post->ID; ?>]"><?php echo wp_get_attachment_image($post->ID,'thumbnail'); ?></a>

                    <?php endwhile; ?>
<?php
$big = 999999999; // need an unlikely integer

echo paginate_links( array(
'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $photos->max_num_pages
) );
endif;
?>
link|improve this answer
Hmmmm this didn't seem to do the trick, the pagination links don't seem to appear. – Dean Elliott Jan 20 at 16:00
Odd. I've tweaked the loop slightly, does that work better? – Chris Cox Jan 23 at 13:04
Now nothing shows up, there's not content being ouput :/ very strange. – Dean Elliott Jan 23 at 14:04
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.