title: Wordpress Pagination for single.php
body: <p>I've implemented category-based numeric pagination in my Wordpress theme:</p>
  
  <p><img src="https://i.stack.imgur.com/2viAm.png" alt="pagination"></p>
  
  <p>What I've done so far is create a custom page template with a list of paginated excerpts. Once a user clicks on an excerpt to view the full article I'd also like to paginate the list of returned articles displayed.</p>
  
  <p>It's my understanding that this is achieved in the theme's 'single.php', though I may be wrong.</p>
  
  <p>The pagination works for my custom template, but when I try implementing the custom query within single.php I think the pagination attempts to find the next page within the article itself, which is not what I'm trying to achieve (because it doesn't exist). I'd like to simply paginate though all the returned articles so the user may navigate next and previous from one article in this category to the next.</p>
  
  <p>I've read a bit about the next/previous links, but I'd rather use something like this <a href="http://bacsoftwareconsulting.com/blog/index.php/web-programming/add-custom-wordpress-pagination-without-plugin/" rel="nofollow noreferrer">blog post by Boutros AbiChedid</a> - I stole this idea for my custom page template, and it's awesome!</p>
  
  <p>I've made a derivative of this class in the theme's 'template.php' as pagination for my custom theme and it works great, but I'm missing something when it comes to getting this to work through the returned single posts.</p>
  
  <p>Should I give up and use another custom page template that displays 1 full article per page where I know my pagination works like a charm? I could do that, but I want to do it right. That's the goal.</p>
  
  <p>Here's what I have so far in single.php:</p>
  
  <pre><code>get_header(); ?&gt;
  
      &lt;div id="primary"&gt;
          &lt;div id="content" role="main"&gt;
  
        &lt;?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?&gt;
        &lt;?php $wp_query = new WP_Query('category_name=news_and_updates&amp;showposts=1&amp;paged=' . $paged);
          while ($wp_query-&gt;have_posts()) : $wp_query-&gt;the_post();
          ?&gt;
  
                  &lt;?php get_template_part( 'content', 'single' ); ?&gt;
  
                  &lt;?php comments_template( '', true ); ?&gt;
  
              &lt;?php endwhile; ?&gt;
  
      &lt;?php if (function_exists("pagination")) {
        pagination($wp_query-&gt;max_num_pages);
      } ?&gt;
  
          &lt;/div&gt;&lt;!-- #content --&gt;
      &lt;/div&gt;&lt;!-- #primary --&gt;
  </code></pre>
  
  
  
  <p>I found this <a href="http://wp.tutsplus.com/tutorials/wordpress-pagination-a-primer/" rel="nofollow noreferrer">tutorial</a> that explains how to tweak pagination by replacing the next/previous links with a 'paginate_links' object. I just can't seem to get it to work.</p>
  
  <p>I know that I'll need to add something like this class from the twentyeleven theme to the custom theme's 'functions.php', then customize it to use numeric pagination and call it either in single.php or single-content.php:</p>
  
  <pre><code>if ( ! function_exists( 'twentyeleven_content_nav' ) ) :
  /**
   * Display navigation to next/previous pages when applicable
   */
  function twentyeleven_content_nav( $nav_id ) {
      global $wp_query;
  
      if ( $wp_query-&gt;max_num_pages &gt; 1 ) : ?&gt;
          &lt;nav id="&lt;?php echo $nav_id; ?&gt;"&gt;
              &lt;h3 class="assistive-text"&gt;&lt;?php _e( 'Post navigation', 'twentyeleven' ); ?&gt;&lt;/h3&gt;
             &lt;div class="nav-previous"&gt;&lt;?php next_posts_link( __( '&lt;span class="meta-nav"&gt;&amp;larr;&lt;/span&gt; Older posts', 'twentyeleven' ) ); ?&gt;&lt;/div&gt;
              &lt;div class="nav-next"&gt;&lt;?php previous_posts_link( __( 'Newer posts &lt;span class="meta-nav"&gt;&amp;rarr;&lt;/span&gt;', 'twentyeleven' ) ); ?&gt;&lt;/div&gt;
          &lt;/nav&gt;&lt;!-- #nav-above --&gt;
      &lt;?php endif;
  }
  endif; // twentyeleven_content_nav
  
  /**
   * Return the URL for the first link found in the post content.
   *
   * @since Twenty Eleven 1.0
   * @return string|bool URL or false when no link is present.
   */
  function twentyeleven_url_grabber() {
      if ( ! preg_match( '/&lt;a\s[^&gt;]*?href=[\'"](.+?)[\'"]/is', get_the_content(), $matches ) )
          return false;
  
      return esc_url_raw( $matches[1] );
  }
  </code></pre>
  
  <p>I'll keep editing this post until I figure this out, unless someone who's done this before answers.</p>