DEV Community

Muhammad Ahmad
Muhammad Ahmad

Posted on • Updated on

How to Add Numbered Pagination in WordPress without using any plugin?

Pagination plays a very important part in websites creation. Basically, it allows users to page back and forth through multiple pages of content. It also helps you to control the length of the page.

Lets discuss some basics but important questions

1. Paginate_links()

Function paginate_links() is the WordPress’s builtin function and can be used to create a paginated link list for any area.

2. Why do you need an unlikely integer in pagination?

The get_pagenum_link( $big ) will create an URL, not a link based on the number provided in the first parameter. This function is used to get the basic pattern for the URL, and the high integer is used here because we must provide an integer as an argument.

3. What is the difference between get_query_var('paged') and get_query_var('page')?

The function get_query_var() is used to get the values from $wp_query public query variables, and in this case that is page and paged. These two parameters and their values are used by WP_Query to calculate pagination and more importantly the offset of posts according to page numbers.
paged used on the home, blog, archive pages, and pages to calculate pagination. 1st page is 0 and from there the number corresponding to the page number.
page use on a static front page and single pages for pagination. By pagination on single pages, I mean that single posts can be broken down into multiple pages.

4. Why we use wp_reset_postdata()?

You need to use wp_reset_postdata() after every custom WP_Query() to resets the value of the global $post variable to the post property of the main query.

Top comments (0)