WordPress.org

Ready to get started?Download WordPress

Forums

Posts pagination. How is the query made available to page 2, 3, 4 and so on (4 posts)

  1. henrywright
    Member
    Posted 10 months ago #

    Can anybody point me towards information about how pagination works? I don't mean how paginate_links() outputs the URLs, I mean how does WP make the post information (the query) available to each page /2/3/4/5 and so on.

  2. wpismypuppet
    Member
    Posted 10 months ago #

    Well, I don't know of any documentation that would explain pagination... But I can tell you how it works (in an over simplified way, of course. SQL is very powerful and too difficult to explain in a forum).

    All WordPress pages/posts/attachments/whatever are loaded through a database. The URL in the address bar contains information that is run through SQL statements to get information from the database. Even if you have "pretty" URLs, the underlying "real" URL contains query string data.

    When you request a page, a SQL statement pulls ids and other query information from the URL and pushes it through a SQL query. This is how it knows what post type and ID to show you. Once the SQL is run, it goes through a hierarchy of page "templates" (or physical pages such as index.php or page.php) to display the database information.

    When you paginate, you are passing a "page number" variable in the URL. The SQL statement uses that variable to know which IDs to get based on a "start" and "end" value. It "fakes" pagination by only showing a certain number of returned SQL table rows. Again, the variable in the URL tells it what to do.

    When you see page /2/3/4/5 and so on, you are looking at the same "physical" page (index.php or page.php, etc.) and it's displaying a different SQL query based on the variable it finds in the URL.

    Hope that sheds some light.

  3. henrywright
    Member
    Posted 10 months ago #

    @wordpressismypuppet thanks for the very thorough explanation, very much appreciated!

  4. wpismypuppet
    Member
    Posted 10 months ago #

    Anytime... glad I could help!

Reply

You must log in to post.

About this Topic

Tags