Pagination: How do I always show ‘previous’?

Looking at the source of paginate_links() it seems there is no option available to always include a previous or next link. The function simply compares the current page number with the total page number to determine whether these links need to be added.

Working around this problem is possible, though. This should get you started:

$page_links = paginate_links(array(
    // Make the function never return previous or next links,
    // we will add them manually.
    'prev_next' => FALSE,

    // Give us back an array, this is the easiest to work with.
    'type' => 'array',

    // + all your other arguments here
));

// Now it is just a matter of adding a previous and next link manually.
// Note: you still have to build the actual prev/next URLs.
$prev_link = '<a href="#">'.__('Previous').'</a>';
$next_link = '<a href="#">'.__('Next').'</a>';

array_unshift($page_links, $prev_link);
$page_links[] = $next_link;

// Output
echo implode($page_links);

Leave a Comment