The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Pagination in Attachments query (3 posts)

  1. bolczan
    Posted 3 years ago #


    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?

  2. esmi
    Forum Moderator
    Posted 3 years ago #

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

  3. bolczan
    Posted 3 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic