I'm looking to set up pagination on my single.php file so I can have my infinite scroll function correctly. I know that pagination can be put on a single post but I somehow need to make the single.php page be able to have an appended variable on the URL. What I mean is if I have this URL:
I would need it to function like this:
It needs to function like that because I have the infinite scroll working on the homepage/main blog page that way and it's picking up the get_query_var('page') variable which doesn't seem to exist in the single.php pages. It keeps looping the first page over and over in the infinite scroll which seems to say to me that it's just defaulting to a value of '1' over and over.
Is there a way to do this?
Thanks for your help!
I've found that I can manually make a 'page' variable by going to the URL here:
The loop at the bottom of the page treats this page as if it's page = 2 even though the same content shows. My assumptions is that the 2 on the end of the page is a get_query_var() variable but it's not necessarily treated as such during my loop/infinite scroll. So I know it exists but is not accessed by the infinite scroll. What do you think the reason is for this?
Here is the pagination code I am using on the single post page for the query (not I am using 'paged' instead 'page' which is how it should be on a single post; I have tried 'page' as well just in case):
$paged = get_query_var('paged'); $wp_query = new WP_Query( array( 'post__not_in' => array(get_the_ID()), 'category__not_in' => 9, 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => 3, 'paged' => $paged ) );
This code works on the homepage for a loop I have there. It does not work on the single.php page though.
So all the help has been great but it still hasn't solved the problem completely. When I echo out the $paged variable on the main page URL I get '0'. If I do it with the url with /2/ appended, it is '2', etc. (so it works then). So it's not recognizing the main page as page '1'. This is with an infinite scroll so it needs to be able to start with 1 and I'm not sure if it's possible to have the infinite scroll work on the single posts pages like that. Any idea why the main URL doesn't have a query var page value of 1?