I am using the following code for my pagination.

// Pagination
function my_paginate_links() {
    global $wp_rewrite, $wp_query;
    $wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;
    $pagination = array(
        'base' => @add_query_arg('page','%#%'),
        'format' => '',
        'total' => $wp_query->max_num_pages,
        'current' => $current,
        'prev_text' => __(''),
        'next_text' => __('next »'),
        'end_size' => 1,
        'mid_size' => 2,
        'show_all' => true,
        'type' => 'list'
    );
    if ( $wp_rewrite->using_permalinks() )
            $pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ) . 'page/%#%/', 'paged' );
    if ( !empty( $wp_query->query_vars['s'] ) )
            $pagination['add_args'] = array( 's' => get_query_var( 's' ) );
    echo paginate_links( $pagination );
}

When it’s on the first page, the ‘previous’ link doesn’t show. I understand why but I’d like it to show because I am designing the site a certain way. Is there a part of the code above I can change to make this happen? I have read through the codex regarding this but couldn’t find an answer that made sense to me. I’d appreciate any guidance. Thank you.

2 Answers
2

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);

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *