Support » How-To and Troubleshooting » Pagination in Attachments query

Pagination in Attachments query

  • Hello

    I’m making page template which queriess its attachments and displays them one by one, 8 on page. I’d like to add “next page” button to it, but all wp_link_pages and other functions seem not to work.
    My query code:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    	$attachments = array(
    		'post_type' => 'attachment',
    		'post_status' => array('publish', 'draft', 'inherit'),
    		'numberposts' => -1,
    		'posts_per_page' => 8,
    		'paged' => $paged,
    	if (have_posts()) : while (have_posts()) : the_post();
    <?php $attachments = get_posts( $args ); ?>
    <?php echo wp_get_attachment_image( $attachment->ID, 'gallery-thumb' ); ?>
    <?php endwhile; else: ?>
    <?php endif; ?>
    <?php echo paginate_links(); ?>

    Why it’s not working? Maybe I’m using wrong function for displaying next page link?

Viewing 2 replies - 1 through 2 (of 2 total)
  • esmi


    Forum Moderator

    Is this the only query and loop on that page? If not, then you shouldn’t be using query_posts() but WP_Query() instead.

    Its the only query and loop on that page.
    Also, somehow I missed <?php next_posts_link(); ?> function, with it it works just fine.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Pagination in Attachments query’ is closed to new replies.