R
R
Rokis2016-02-03 12:47:27
WordPress
Rokis, 2016-02-03 12:47:27

Why is pagination not working on the archives page in Wordpress?

I tried many ways to fix this problem, nothing helped. I use a custom URL: /%category%/%postname%
There is a pagination code:

function wp_corenavi() {
  global $wp_query;
  $pages = '';
  $max = $wp_query->max_num_pages;
  if (!$current = get_query_var('paged')) $current = 1;
  $a['base'] = str_replace(999999999, '%#%', get_pagenum_link(999999999));
  $a['total'] = $max;
  $a['current'] = $current;

  $total = 0;
  $a['mid_size'] = 3;
  $a['end_size'] = 2;
  $a['prev_text'] = '«';
  $a['next_text'] = '»';
  
  if ($max > 1) echo '<div class="navigation">';
  if ($total == 1 && $max > 1) $pages = '<span class="pages">Страница ' . $current . ' из ' . $max . '</span>'."\r\n";
  echo $pages . paginate_links($a);
  if ($max > 1) echo '</div>';
}
//end

This code normally displays pagination on the main page, but does not work on the archives page. At first, it just gave a 404 error when going to the second and further pages. I have corrected. Then the same page began to remain. The URL changes, but the page remains. For example, www.site.ru/knigi/page/2
www.site.ru/knigi/page/3
www.site.ru/knigi/page/4 There are

no problems when adding /category/
www.site.ru/ to the URL category/books/page/2 - displayed normally.
I read a bunch of different articles on this topic - nothing helped. I don't use global variable anywhere. I output ALL posts through the standard loop:
<?php if( have_posts() ){ while( have_posts() ){ the_post(); ?>

Updated permalink settings.
Please tell me what is the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
WP Panda, 2016-02-03
@Rokis

Use the core pagination get_the_posts_pagination()

I
Igor Vorotnev, 2016-02-03
@HeadOnFire

I can't understand why you even expect a url without a category base to work? That is, www.site.ru/knigi/page/2 and should not work, at the same time, www.site.ru /category/ knigi/page/2 should work, because it has a category base (highlighted in bold ). In general, everything is OK, as it should be. For some reason you are just waiting for atypical behavior where it should not be. This time.
Two - enough already to invent some crutches for pagination. There are built-in tools for every taste.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question