How Does Pagination works?

Hello, I am trying to paginate Blog posts, is there any documentation or instructions to query posts or set posts per page?

You can use libraries.source.parse to get an object with { page, path, query} from a link (like state.router.link) and libraries.source.stringify to generate a link back.

source should return totalPages of a fetched page with state.source.get.

// Get the page of the current URL:
const { path, page, query } = libraries.source.parse(state.router.link);
// Get the URL of the next page:
libraries.source.stringify({ path, page: page + 1, query });
// Get the total number of pages:
const { totalPages } = state.source.get(state.router.link);

There is a easy example in mars-theme:

And a more complex example in twenty-nineteen:

1 Like

The problem i am having is posts per page limited to 10, is there any way i can change that from backend? i tried to change the values in wordpress settings but it somehow applied to my Custom Post.

You can add params to @frontity/wp-source package at frontity.settings.js and select there the number of posts per page.

...
{
      "name": "@frontity/wp-source",
      "state": {
        "source": {
          "api": "https://test.frontity.io/wp-json",
          "params": {
            "per_page": 20
          }
        }
      }
},
...

There is a more detailed explanation at @frontity/wp-source docs.

Is this what you were looking for?

1 Like

:+1::+1:

By the way, the params setting was introduced in wp-source v1.3.1 so make sure to update it to the last version: Frontity update: 10 September 2019

Thanks @SantosGuillamot but why its effecting my Custom Post Data, i believe it has nothing to do with this.

What do you mean by Custom Post Data?