Pagination with multiple loops in single.php using custom permalink structure (1 post)

  1. Kevin Daniels
    Posted 4 years ago #

    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:

    but I don't really want to change that. Any suggestions?

      $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
      $post_per_page = 2;
        '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>
      <?php else : ?>
    		<h2 class="center">Nothing Found</h2>
    	<?php endif;
    	$wp_query = $temp;  //reset back to original query

Topic Closed

This topic has been closed to new replies.

About this Topic