Yet another pagination issue… I can't see why it won't work!
-
I’m using a child-theme of devdm’s Bootstrap template and I’ve created a static page template which contains a loop to display all posts from a parent category called Portfolio.
This parent category has sub-categories, and using the WP_Query below, I am able to display as many posts as I wish per page with no issues.
I’m trying to add Pagination now, and I’ve followed every tutorial I can find but for some reason it won’t work. All I want is a simple ‘More’ link at the bottom of my loop using
next_posts_link( 'More' )
My code is as follows:
<?php $paged = ( get_query_var('page') ) ? get_query_var('page') : 1; ?> <?php $category = get_post_meta($post->ID, 'portfolio category', true); ?> <?php $query = new WP_Query( array( 'posts_per_page' => 3, 'cat' => $category, 'paged' => $paged )); ?> <?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?> // Stuff that prints post details (works) <?php endif; ?> <?php endwhile; ?> <?php next_posts_link( 'More' ); ?> wp_reset_postdata(); else : ?> <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p> <?php endif; ?>
The code is really broken-down, I know. The pagination does nothing at all here. I’ve inspected the page source, and nothing is printed at all.
Just to be clear, this is on a custom page template. i.e., the header of this file says:
Template Name: Portfolio List
I’d appreciate any help!
- The topic ‘Yet another pagination issue… I can't see why it won't work!’ is closed to new replies.