G
G
German Zuiakov2021-08-11 23:40:37
WordPress
German Zuiakov, 2021-08-11 23:40:37

Why is pagination not working?

function pagination() {
  global $wp_query;
  if ( $wp_query->max_num_pages <= 1 ) return; 
  $big = 999999999; // need an unlikely integer
  $pages = paginate_links( array(
        'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
        'format' => '?paged=%#%',
        'current' => max( 1, get_query_var('paged') ),
        'total' => $wp_query->max_num_pages,
        'type'  => 'array',
        'prev_text'	=> ( '<span class="icon icon-back"></span>' ),
    	'next_text'	=> ( '<span class="icon icon-back next"></span>' ),
    ) );
    if( is_array( $pages ) ) {
        $paged = ( get_query_var('paged') == 0 ) ? 1 : get_query_var('paged');
        echo '<nav><ul class="pagination">';
        foreach ( $pages as $page ) {
                echo "<li class='page-item'>$page</li>";
        }
       echo '</ul></nav>';
  }
}


Pagination does not work, namely, it goes to another page with the same posts

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Zolin, 2021-08-12
@artzolin

And won't work. Use the_posts_pagination()or the_posts_navigation(). For customization, you can see the code of these functions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question