Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Unilever\ATH\Theme;
- if ( ! function_exists( 'add_action' ) ) {
- exit(0);
- }
- class Pagination
- {
- /**
- * args
- *
- * @since 0.0.1
- * @var array
- */
- private $args = array();
- /**
- * WP_Query wordpress
- *
- * @since 0.0.1
- * @var object
- */
- private $wp_query;
- public function __construct( $args = array(), $attrs = array() )
- {
- $defaults = array(
- 'template' => '',
- 'class_container' => '',
- 'class_button' => 'btn-s',
- 'class_title' => 'btn-s-text',
- 'title' => __( 'Show More', App::TEXTDOMAIN ),
- 'paged' => 1,
- 'lazyload' => 3,
- 'show_always' => false,
- 'query' => null,
- 'wait' => __( 'Wait...', App::TEXTDOMAIN ),
- );
- $this->initialize( wp_parse_args( $args, $defaults ), $attrs );
- }
- public function initialize( $args, $attrs = array() )
- {
- $this->args = $args;
- $this->set_query();
- if ( ! $this->is_pages() )
- return;
- $this->render( $attrs );
- }
- public function set_query()
- {
- global $wp_query;
- if ( is_null( $this->args['query'] ) ) {
- $this->args['query'] = $wp_query;
- }
- $this->wp_query = $this->args['query'];
- }
- public function is_pages()
- {
- return ( $this->wp_query->max_num_pages > 1 || $this->args['show_always'] );
- }
- public function render( $attrs = array() )
- {
- $defaults = array(
- 'data-query' => json_encode( $this->wp_query->query ),
- 'data-max' => $this->wp_query->max_num_pages,
- 'data-paged' => $this->args['paged'],
- 'data-template' => $this->args['template'],
- 'data-load-more' => $this->args['lazyload'],
- 'class' => $this->args['class_container'],
- 'style' => ( $this->wp_query->max_num_pages <= 1 ) ? 'display:none' : '',
- 'data-label-wait' => $this->args['wait'],
- 'data-label-trigger' => $this->args['title'],
- );
- $attrs = wp_parse_args( $attrs, $defaults );
- ?>
- <div data-component="paginator" <?php echo $this->get_attr_html( $attrs ); ?>>
- <a class="<?php echo esc_attr( $this->args['class_button'] ); ?>" data-action="next-page" data-element="trigger" href="javascript:void(0);">
- <span class="<?php echo esc_attr( $this->args['class_title'] ); ?>"><?php echo esc_html( $this->args['title'] ); ?></span>
- </a>
- </div>
- <?php
- }
- public function get_attr_html( $attrs )
- {
- $fields = array();
- foreach ( $attrs as $attr => $value ) {
- $fields[] = "{$attr}='{$value}'";
- }
- return implode( ' ', $fields );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement