DEV Community

Muhammad Ahmad
Muhammad Ahmad

Posted on • Edited on

1 1

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.

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay