WordPress.org

Ready to get started?Download WordPress

Forums

Pagination in Attachments query (3 posts)

  1. bolczan
    Member
    Posted 1 year ago #

    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:

    <?php
    $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,
    	);
    	query_posts($attachments);
    
    	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: ?>
    
    NO ATTACHMENTS
    
    <?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 1 year 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
    Member
    Posted 1 year 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