Click here to Skip to main content
Click here to Skip to main content

WordPress – Numbered Page Navigation Without Any Plugins

, 13 Feb 2013
Rate this:
Please Sign up or sign in to vote.
How to add a numbered page navigation in any new or existing WordPress theme without any plugins.
Numbered Page Navigation - WordPress
Numbered Page Navigation

Numbered page navigation is not available in WordPress features. WordPress, instead uses (Previous Page/Post – Next Page/Post) navigation style. however; there are a number of plug-ins for this solution and some are listed below.

  • Zamango Page Navigation
    • Zamango Page Navigation creates pagebar on lists (for ex. on category or search results) and Next Post & Previous Post links on each post.
  • WP-PageNavi
    • Replace the old ← Older posts | Newer posts → links to numbered link page navigation.
  • WP Paging
    • This plugins is based on a core page number function called paginate_links.
But if you don’t want to install any plugins for this solution and trying to code your own numbered page navigation in WordPress theme. Then, this article will show you how to add a numbered page navigation in any new or existing WordPress theme without any plugins.

The easiest way to create numbered page navigation is to use the paginate_links WordPress function which requires an array of parameters and returns an array or string of links.

Usage:

<?php echo paginate_links( $args ) ?>

Default Arguments:

<?php 
    $args = array(
    'base' => '%_%',
    'format' => '?page=%#%',
    'total' => 1,
    'current' => 0,
    'show_all' => False,
    'end_size' => 1,
    'mid_size' => 2,
    'prev_next' => True,
    'prev_text' => __('« Previous'),
    'next_text' => __('Next »'),
    'type' => 'plain',
    'add_args' => False,
    'add_fragment' => ''
); 
?>

Visit this page to learn more about arguments.

Example:

Following script returns numbered page navigation in list (li) format.

<!-- Paging Start -->
<div class="paging">
<ul>
    <?PHP
        global $wp_query;
        $big = 999999999; // need an unlikely integer
        $args = array(
            'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
            'format' => '?page=%#%',
            'total' => $wp_query->max_num_pages,
            'current' => max( 1, get_query_var( 'paged') ),
            'show_all' => false,
            'end_size' => 3,
            'mid_size' => 2,
            'prev_next' => True,
            'prev_text' => __('&laquo; Previous'),
            'next_text' => __('Next &raquo;'),
            'type' => 'list',
            );
        echo paginate_links($args);
    ?>
    </ul>
</div>
<!-- // Paging End -->

You can add this script in files (index.php, archives, tag.php, category.php, *****-loop.php, etc..) at the end of the page or after loop finishes or search for posts_nav_link at the page which will look similar to code below. Put the script after the code line below or replace the code line below with above script.

<div style="text-align:center;">
<?php posts_nav_link(' &#183; ', 'previous page', 'next page'); ?>

Adding CSS style:

Use CSS below to add style into numbered page navigation or customize the CSS to your theme color and schema.

.paging ul {
    float:right;
}
.paging ul li {
    float:left;
    margin:0px 0px 2px 0px;
}
.paging ul li a{
    background-color:#000;
    color:#FFF;
    padding:7px 11px 7px 11px;
    font-size:12px;
    border:solid 2px #000;
    margin-left:1px;
}
.paging ul li .current, .paging ul li .dots  {
    background-color:#FFF;
    color:#000;
    padding:7px 11px 7px 11px;
    font-size:12px;
    border:solid 2px #000;
    margin-left:1px;
}
.paging ul li a:hover {
    background-color:#333;
}

References:

Also, this post provides some very good CSS styles for numbered page navigation.

Conclusion:

Finally, By using paginate_links funciton, you should have numbered page navigation without any plugins in your theme.

The post WordPress – Numbered Page Navigation Without Any Plugins appeared first on Noor Ahmad Feroozi.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Noor Ahmad Feroozi
Software Developer (Senior) Ministry of Education
Afghanistan Afghanistan
Over eight years of IT industry experience, and have been a part of design and development projects for many exceptional companies during those years, including Kabul Cyber Park, Alpha Omega Services, Ministry of Defense, Spacetech ICT Solutions, Ministry of Education and many others.
 
Technologies I use are standards-based XHTML, CSS, JavaScript, jQuery, PHP, ASP.Net, C#.Net, MS SQL, MySQL and SQLite. Each project I develop is built to be search engine and user friendly, using the latest development principles and techniques. To find out more about what I can do for you, check out my work at http://recentsolutions.net, or get follow me on http://twitter/naferoozi
Follow on   Twitter   Google+

Comments and Discussions

 
QuestionThanks PinmemberMohammad Zunayed Hassan29-Jan-14 16:32 
QuestionVote 5 PinmemberMusthafa (Member 379898)2-Nov-13 20:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 13 Feb 2013
Article Copyright 2013 by Noor Ahmad Feroozi
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid