Ask your WordPress questions! Pay money and get answers fast! (more info)

WP_LINK_PAGES Next/Previous and Numbers Problem WordPress

  • SOLVED

I have a code to add both page numbers and next/previous links in a function which replaces wp_link_pages. I have modified the code, however, there is still a few problems with it.

1.When a user is past page 1 (for example, on page 3) the link to page 1 always links to the current page (in this example, page 3) - see the example at this link

2. When a user is on page 2, the previous button links to the current page (page 2), this only happens on page 2 - see the example at this link

<strong>Fix these two problems, provide the modified code, and that sweet, sweet, cash is yours.</strong>

In functions.php

function tp_link_pages() {
global $page, $numpages;

echo paginate_links( array(
'format' => get_permalink() . '&page=%#%',
'current' => $page,
'total' => $numpages
) );
}


How I call it:

<?php tp_link_pages(); ?>

Answers (1)

2013-01-07

Naveen Chand answers:

If you are using pretty permalinks structure, then the below code can work:

function tp_link_pages() {

global $page, $numpages;

echo paginate_links( array(

'format' => '/page/%#%',

'total' => $numpages

) );

}


If you are not using the pretty permalink structure, then this below mentioned code can work:

function tp_link_pages() {

global $page, $numpages;

echo paginate_links( array(

'format' => '?page=%#%',
'total' => $numpages

) );

}

You don't have to set <strong>current</strong>. Its default value is 0. And hence, the current page will differentiate from others in the function.

Try it and let me know if it works.
<em>Side Note: A dollar can't buy "two" sweets these days.</em>