Pagination with multiple loops in single.php using custom permalink structure
-
I feel this is fairly complex. This works perfectly inside a normal custom page template applied to a page but as soon as I put it into “single.php” the pagination no longer works. It redirects to the page itself and only displays the first page of posts tagged with ‘sports’.
My permalink structure is:
/%category%/%postname%/but I don’t really want to change that. Any suggestions?
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $post_per_page = 2; $args=array( 'tag' => 'sports', 'paged' => $paged, 'posts_per_page' => $post_per_page, ); $temp = $wp_query; $wp_query = null; $wp_query = new WP_Query($args); if( have_posts() ) : while ($wp_query->have_posts()) : $wp_query->the_post(); ?> <h3><?php the_title(); ?></h3> <?php endwhile; ?> <div class="navigation"> <div class="alignleft"><?php next_posts_link('« Older Entries') ?></div> <div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div> </div> <?php else : ?> <h2 class="center">Nothing Found</h2> <?php endif; $wp_query = $temp; //reset back to original query ?> </div>
The topic ‘Pagination with multiple loops in single.php using custom permalink structure’ is closed to new replies.