WP paginate shows all the pages and is not limited, Why?

In my wordpress blog, i use wp paginate (default plugin) for pagination. I use a custom query to list the posts. Please see this link

Everything works fine. I show six posts per page (admin setting) and the number of pages are correct. But my problem is all the pages are shown in the pagination.

Read More

i.e. 1|2|3|4|5|6|7|8|9|10|>, but I want it like this |1|2|3|4|…|10|>.

What should I do, I’m new to wordpress. Can anyone help please?

Note:

  1. No modifications done to wp paginate plugin.

  2. Also changed the pagination settings in backend (wp-admin) to show 3 pages front and back of the current page and it doesn’t work.

my index.php looks like this:

<?php 
    $paged = get_query_var('paged');
    $args = array(
    'post_type' => 'post',
    'meta_key'  => 'wpcf-fn',
    'orderby'   => 'meta_value',
    'order' =>  'ASC',
    'paged' => $paged
    );
    $cust_query = new WP_Query( $args );
    $temp = $wp_query;
    $wp_query = $cust_query;
?>
<div> *** contents rendered on the page *** </div>
<div id="navigation" class="clearfix">
    <?php if(function_exists('wp_paginate')) : wp_paginate(); ?>
</div>
<?php $wp_query = $temp;?>

Related posts

Leave a Reply

1 comment

  1. <?php
    global $wp_query;
    
    $big = 999999999; // need an unlikely integer
    
    echo 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,
        'show_all' => FALSE, //this will make paginate not to show all links.
        'end_size' => 2, //will show 2 numbers on either the start and the end list edges. 
        'mid_size' => 0 //so that you won't have 1,2...,3,...,7,8
    ) );
    ?>
    

    More details: https://developer.wordpress.org/reference/functions/paginate_links/