-
Notifications
You must be signed in to change notification settings - Fork 7
Pagination Component
The Pagination
component is a generic component. It is primarily a wrapper for WordPress' core function paginate_links()
(although can be used outside the context of a WP_Query). Pagination
components contain any number of children Pagination_Item
components.
To use a Pagination
component you should initialise the component, define the base_url
config value, and set the query. The component will automatically generate children Pagination_Item
components that correspond to each link.
You can modify the children components to modify the pagination itself (ex. inserting additional controls, or removing superfluous ones (like ...
results).
( new \WP_Components\Pagination() )
->set_config( 'url_params_to_remove', [ 'path', 'context' ] )
->set_config( 'base_url', '/search/' )
->set_query( $this->query );
-
base_url
This is the path of your route before/page/
. For example, if you are paginating search results at/search/page/2/
your base_url should be/search/
. A term archive may look like/category/sports/page/1/
, where the base_url would be/category/sports/
-
url_params_to_remove
This config allows you to define an array of query arguments to remove from your pagination links. This was implemented for Irving as a solution to strip the API query vars from results.