Responsive Pagination plugin lets you configure your paginations to adapt to different screen size. Your paginations can be shown differently based on browser width as in responsive web design concept.
For instance, you might want to have a longer pagination with many page numbers when your site visitors are using desktops and large screens, but need shorter pagination with only
Prev and
Next link when they're using phones.
You may try using this plugin when you found your theme is not doing well with the responsive design on its pagination. This plugin lets you configure manually to the desired breakpoints.
Two Different Methods to Apply Responsive Pagination
You can choose the way you want to apply responsive pagination.
Method A : Convert Existing Paginations (No Coding Required)
This method will convert the existing paginations from your theme into responsive paginations without needs to add any WordPress shortcode or PHP code. You only need to fill the selectors (
CSS or
jQuery-like selector) of the existing pagination elements. You'll input the selectors in Admin Settings Page (
Settings > Responsive Pagination)
Method B : Create new Pagination Programmatically from Scratch
This method will need you to insert PHP code into template files directly using
Responsive Pagination API. This method supports queries using
WP_Query, or even something more generic without
WP_Query.
Responsive Pagination API (For Programmatic Usage)
Note : This API section is a short guide for creating responsive pagination programmatically. However, there is easier solution using this plugin without touching any code - that is by converting your theme's existing pagination from within Admin Settings Page with just providing its CSS/jQuery selector.
If you want to create responsive pagination programmatically, this plugin adds new function for you to use, which will render a new pagination where you put the function.
```
```
Parameters :
$id
: (string) (required) ID for the new pagination you want to create in kebab-case format.
-
$args
: (WP_Query | array) (required) WP_Query instance, or an associative array contains :
-
$current
: (int) Current page
$total
: (int) Total pages
$urlFirstPage
: (string) URL for first page
$urlPattern
: (string) URL pattern for this pagination by using {pagenum}
tag.
Note : Pagination settings and Breakpoint Configurations are still configured from within Admin Settings Page.
Example (For Programmatic Usage)
Example for creating pagination for posts within main loop using
WP_Query. This also works with custom post type as long as you have
WP_Query within loop.
```
```
Example for creating a more generic pagination by providing your own data for current page, total pages, URL first page, and URL pattern without
WP_Query.
```
$my_current_page, // your current page here
'total' => $my_total_pages, // your total page here
'url_first_page' => '
https://www.example.com/archives/', // URL when current page = 1
'url_pattern' => '
https://www.example.com/archives/page/{pagenum}' // the pattern using {pagenum} tag
) );
}
?>
```
The installation is pretty standard, just like any other plugins.
- install the plugin through the WordPress admin on 'Plugins' screen directly, or upload the plugin files to the
/wp-content/plugins/responsive-pagination
directory.
- Activate the plugin through the 'Plugins' screen in WordPress admin.
- Use "Settings > Responsive Pagination" screen within WordPress admin to configure the plugin.