0

I want to modify the output of wp_link_pages.

Basically what I need is to show Previous and Next buttons and current page/total number of pages. I created the Previous and Next button. Now in between them I want to add a current page and the total pages number.

Here is my code

wp_link_pages( array(
    'before' => '<div class="page-links">' . __(''),
    'after' => '</div>',
    'next_or_number' => 'next',
    'nextpagelink' => __('Next'),
    'previouspagelink' => __('Previous'),
    'pagelink' => '%',
    'echo' => 1,
) );

I am not sure what to do. The effect I want to get is just like below image.enter image description here

0

You are using the wrong function, please check this link https://codex.wordpress.org/Function_Reference/paginate_links

As you can see your code should be

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,
  'next_text' => '<i class="fa fa-angle-right"></i>',
  'prev_text' => '<i class="fa fa-angle-left"></i>'
) );

if you are using a custom query with WP_Query() your code should be similar to:

$query_post = new WP_Query(array(
...
'paged' => get_query_var('paged'),
...
));


$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' => $query_post->max_num_pages,
  'next_text' => '<i class="fa fa-angle-right"></i>',
  'prev_text' => '<i class="fa fa-angle-left"></i>'
) );

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.