API Guide

Introduction

Responsive Pagination API is used for creating responsive pagination programmatically. At the moment, we only support integration for WordPress platform.

This API could be used to create generic pagination, not only post archive or custom post type archive. You would need to query your current page and total pages by your own. Put your code in the appropriate template files in your theme which render the pagination. This may involve replacing the theme’s pagination code.

Info : There is an easier solution to implement responsive pagination by converting existing theme’s pagination without putting any PHP code. You just need to input CSS/jQuery element selector of the existing pagination. If you inclined to that way, see Getting Started.

Responsive Pagination API

<?php  create_responsive_pagination( $id, $args )  ?>

Parameters :

  • $id : (string) (required) New ID in kebab-case format.
  • $args : (WP_Query | array) (required) Either WP_Query instance, or an associative array contains the following :
    • $current : (int) Pagination’s current page
    • $total : (int) Pagination’s total page
    • $urlFirstPage : (string) Full URL for the first page*
    • $urlPattern : (string) Full URL pattern for the rest of pages, using {pagenum} tag.

Additional Notes

  • Pagination settings & breakpoint configurations are still configured from admin settings screen within “Pagination Settings” tab.
  • It is recommended to wrap the API with function_exists()¬†conditional function.
  • Sometimes the first page url is just www.example.com/archive/, instead of www.example.com/archive/page/1, so $urlFirstPage¬†and $urlPattern should always be present when passing associative array $args.

Examples

Some examples in WordPress platform.

Example Using Global WP_Query

If your pagination is going to be inside the main loop, you can utilize global instance of WP_Query.

<?php
    global $wp_query;

    if ( function_exists( 'create_responsive_pagination' ) ) {
        create_responsive_pagination( 'my-pagination-id', $wp_query ); 
    }
?>

Example Using Custom Instance of WP_Query

If your pagination is going to be inside your custom loop, you can use the corresponding custom WP_Query instance,

<?php
$custom_query = new WP_Query( $query_args );

while ( $custom_query->have_posts() ) {
    // ... your code ...

    if ( function_exists( 'create_responsive_pagination' ) ) {
        create_responsive_pagination( 'my-pagination-id', $custom_query ); 
    }

    // ... the rest of your code ...
} 
?>

Example of Generic Pagination

If you’re creating a generic pagination by providing your own calculation for current page and total page, you can pass an associative array instead of WP_Query instance.

<?php
if ( function_exists( 'create_responsive_pagination' )) {
    create_responsive_pagination( 'my-pagination-id', array(
        'current'  => $my_current_page,
        'total'  => $my_total_pages, 
        'url_first_page'  => 'https://www.example.com/uncategorized/',
        'url_pattern'  => 'https://www.example.com/uncategorized/page/{pagenum}' 
    ));
}
?>