0

So my blog index page which displays all blog posts with pagination is at /my-blog/

Page two is at /my-blog/2

When I'm on any page but the first (or if i use /1 for the first page) paginate_links() is able to correctly add the right class to the current page's link to indicate we are on that page. However, when I am on the first page with the url being /my-blog/ it fails to do this correctly because the 'base' and 'format' settings are looking for '/my-blog/%_%' and '/my-blog/%#%'respectively.

I am not using a loop, instead using get_posts. How can I get the pagination to correctly indicate that the user is on the first page when the path does not include a number (/my-blog/)?

$paged = get_query_var('page');
$args = array('paged' => $paged);
$wp_query = new WP_Query($args);

echo paginate_links( array(
  'base' => '/my-blog/%_%',  
  'format' => '/my-blog/%#%',  
  'current' => max( 0, get_query_var('page') ),
  'total' => $wp_query->max_num_pages,
  'end_size' => 8,
  'mid_size' => 2));
| improve this question | | | | |
0

You should change the first line of your code to:

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

So it sets $paged to 1, when your are on the first page.

| improve this answer | | | | |
  • Wonderful! Makes sense now. In my code I also had to make sure to use the $paged var in the 'current' arg as the above code was just pulling it from get_query_var originally. Thanks! – rabbitfeetz Oct 3 '14 at 17:33

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.