Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

By default, WordPress shows previous and next links when content is split onto different pages. Is there a way to get it to use proper pagination (with numbers), perhaps with a plugin?

share|improve this question

2 Answers 2

up vote 5 down vote accepted

yes, try wp-pagenavi http://wordpress.org/extend/plugins/wp-pagenavi/

share|improve this answer

Add to Functions.php

/* Numeric Pagination ********************************************/

function numeric_pagination ($pageCount = 9, $query = null) {

    if ($query == null) {
        global $wp_query;
        $query = $wp_query;
    }

    if ($query->max_num_pages <= 1) {
        return;
    }

    $pageStart = 1;
    $paged = $query->query_vars['paged'];

    // set current page if on the first page
    if ($paged == null) {
        $paged = 1;
    }

    // work out if page start is halfway through the current visible pages and if so move it accordingly
    if ($paged > floor($pageCount / 2)) {
        $pageStart = $paged - floor($pageCount / 2);
    }

    if ($pageStart < 1) {
        $pageStart = 1;
    }

    // make sure page start is
    if ($pageStart + $pageCount > $query->max_num_pages) {
        $pageCount = $query->max_num_pages - $pageStart;
    }

?>
    <div id="archive_pagination">
<?php
    if ($paged != 1) {
?>
    <a href="<?php echo get_pagenum_link(1); ?>" class="numbered page-number-first"><span>&lsaquo; <?php _e('<< First', 'global'); ?></span></a>
<?php
    }
    // first page is not visible...
    if ($pageStart > 1) {
        //echo 'previous';
    }
    for ($p = $pageStart; $p <= $pageStart + $pageCount; $p ++) {
        if ($p == $paged) {
?>
        <span class="numbered page-number-<?php echo $p; ?> current-numeric-page"><?php echo $p; ?></span>
<?php } else { ?>
        <a href="<?php echo get_pagenum_link($p); ?>" class="numbered page-number-<?php echo $p; ?>"><span><?php echo $p; ?></span></a>

<?php
        }
    }
    // last page is not visible
    if ($pageStart + $pageCount < $query->max_num_pages) {
        //echo "last";
    }
    if ($paged != $query->max_num_pages) {
?>
        <a href="<?php echo get_pagenum_link($query->max_num_pages); ?>" class="numbered page-number-last"><span><?php _e('>> Last', 'global'); ?> &rsaquo;</span></a>
<?php } ?>

    </div>

<?php } ?>

Before The Loop

<?php
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts("showposts=6&paged=$page");
?>

After The Loop Between endwhile and else

<?php numeric_pagination(); ?> 
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.