How to Add Numeric Page Number in Wordpress Theme

Published by admin on

How to Add Numeric Page Number in WordPress Theme

Methods to add page numbers in WordPress Using Manual method and the Pagination plugin

This is a question every blogger need and wants to ask. Most of the free themes used in WordPress usually lack this feature which are most demanded and required feature. They display the pagination link as “Older Post” and “Older Posts” at the bottom of WordPress website/blog homepage or at the bottom of website archive page.

However, there are several WordPress themes that provide pagination feature by default which can be easily configured and customized. These are numeric pagination and  can be used easily. There are several websites which use this numeric pagination system to make visitor easy to navigation between older and new posts easily.

These Numeric pagination are most user friendly and SEO friendly. So if you really want to know all about the pagination and how to add numeric pagination system on your WordPress website archive then stick to the post and you will come to know.

In addition there are several plugins which let you enable the numeric pagination to your WordPress website. We shall discuss the manual and automatic method in details. The goal is to replace the default Older and Newer pagination links at the bottom of archive pages with easy to navigate page numbers.

Add Numeric Pagination in Your WordPress Website Manual and Pagination plugin Method

There are two applied and tested method to add page number system at the end of your WordPress website. These numbers usually appear at the end of your WordPress Website to make user easy to navigate between the archive. The manual method of adding the pagination at the bottom of your theme includes some short of codes to be manually inserted inside the Theme files. The manual pagination methods requires some advance skills of codes and theme files. Whereas the other method includes some installation of WordPress Plugins and configuration. Which is easy and wuick method to add page numbers at the end of your WordPress website theme.

 Adding Numeric Page Number in WordPress-Manual Method

 This method of adding page numbers in the pagination area of a WordPress website requires some advance skills about codes and method. If you are having trouble to configure the default pagination system on your WordPress website the try this method.

Note: Before you start playing with codes and files it is recommended that you take a backup of your entire Wordress Website.

In order to add page numbers or the pagination system at the bottom of the WordPress website archive we need to make some modification on couple of PHP files under the hood. However, most of the settings are been made to function.php file under the Theme editor tab. We have two section of the codes, One will replace the default “older posts” and “newest Posts” section link and the another part of code will calculate the number of posts available on the Website. Here is the first section of codes which is to be placed inside the “function.php” of your theme or child theme of your wordpress website on order to add number pagination.

Code 1.

function pagination_bar() {
    global $wp_query;
    $total_pages = $wp_query->max_num_pages;
    if ($total_pages > 1){
        $current_page = max(1, get_query_var('paged'));
        echo paginate_links(array(
            'base' => get_pagenum_link(1) . '%_%',
            'format' => '/page/%#%',
            'current' => $current_page,
            'total' => $total_pages,
        ));
    }
}

Here we have included the global $wp_query object in order to access all the posts. The next step will get the number of maximum posts should be displayed n a single page. The max_num_pages function will help us to determine the number of pages per page.

In addition this will enable to perform a condition which will determine if there are enough post to use pagination on the Website. And at the end get_query_var is used to figure out the number of current page the user on.

The last step is to use the paginate_links function to actually render our list of pages, as well as a previous and next button. For the “base” parameter, we pass our initial page. The “format” parameter is where we can specify how we want the URL to change when subsequent pages are accessed.

In the above example, pages will be rendered as http://site.com/page/2, etc. The last thing we do is use the variables we collected to define what page we are currently on, and how many pages there are total. Using this data, WordPress can render for us a standard pagination bar.

To actually add this pagination, go to the page you want to add the functionality too (typically index.php) and paste the following code just before the end of our loop, after the “endif” statement, but before “endwhile”.

<nav class="pagination">
<?php pagination_bar(); ?>
</nav>

Adding Numeric Page Number in WordPress-Pagination plugin Method


admin

admin

A blogger Enthusiast and SEO, SERP and Digital Marketing Mentor.

Leave a Reply

5 Comments

Clemmie · December 10, 2018 at 3:53 am

This info is worth everyone’s attention. How can I find
out more?

olej konopny · December 10, 2018 at 11:22 am

whoah this weblog is great i really like reading your posts.
Stay up the great work! You understand, many people are hunting around for
this information, you can help them greatly.

Trina · December 12, 2018 at 11:50 am

This website is my inhalation, rattling wonderful style and Perfect subject matter.

tabletten für muskelaufbau · December 22, 2018 at 8:51 pm

Howdy! This blog post could not be written any better!
Going through this post reminds me of my previous roommate!
He constantly kept preaching about this. I’ll send this information to him.
Fairly certain he’s going to have a great read. Thank you for sharing!

adelaide weather · January 8, 2019 at 3:45 am

Excellent post. I was checking constantly this blog and I am impressed!
Extremely helpful information specifically the last part 🙂 I care for such
information much. I was seeking this particular
information for a long time. Thank you and best of luck.

Leave a Reply

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