I want the main front-page loop to show in a section on both index.php AND single.php templates, with pagination.

Pagination works fine on the homepage, but not on single posts. This is the code (outside the loop that gets the single post):

  'post__not_in' => array($post->ID),
  'caller_get_posts' => 1,
  'posts_per_page' => 20,
  'paged' => ''.get_query_var('paged').'' ));
if (have_posts()) : while (have_posts()) : the_post();
  include 'post.php';
endwhile; endif;

I have tried several other functions for navigation with similar results: On posts, /page/2 is added to the end of the permalink and then ignored.

(Final goal is to have infinite scroll working inside single posts too. The result up to now can be seen here - www.riscograma.ro - the middle column being the main loop.)

So, can pagination inside single.php be done?

  • You can paginate a secondary Loop, though it tends to make navigation confusing IMO. What the site you reference is doing though is loading posts via AJAX and that is what you will need to do to duplicate that. I would suggest that you look at the infinite scroll posts here and see if you can get started. – s_ha_dum Apr 21 '13 at 14:46
  • 4
    Also, don't use query_posts – s_ha_dum Apr 21 '13 at 14:50
  • The AJAX I use needs working pagination in order to do its job. I have query_posts because, for some reason, it falls back to reloading the first page on single.php which is better than nothing (wp_query) – user23068 Apr 21 '13 at 14:55
  • 1
  • Already tried the former, now tried the latter, neither does it. I must be doing something wrong, I suppose the idea is to have the pagination as query (?paged=2 instead of /page/2/) but i don't know how to get there. Is it a canonical redirect I need to overwrite? – user23068 Apr 21 '13 at 16:31

Disabling canonical redirect (crudely) gets the job done.

  • 3
    An explanation would be useful. – fuxia Apr 25 '13 at 9:28
  • Updated it. To remove canonical redirect, you add the following to functions.php: remove_filter('template_redirect', 'redirect_canonical'); – user23068 Apr 25 '13 at 10:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy