1: <?php
2: /**
3: * Elementor archive pagination widget.
4: *
5: * @package EPL
6: * @subpackage PageBuilders/Elementor/Widgets/Archive
7: * @since 3.6.0
8: */
9:
10: if ( ! defined( 'ABSPATH' ) ) {
11: exit;
12: }
13:
14: /** Pagination for the current Elementor/EPL archive query. */
15: class EPL_Elementor_Pagination extends \Elementor\Widget_Base {
16: use EPL_Elementor_Dynamic_Widget;
17:
18: /**
19: * Widget name.
20: *
21: * @since 3.6.0 New: Elementor widgets (beta).
22: */
23: public function get_name() {
24: return 'epl-pagination';
25: }
26:
27: /**
28: * Widget title shown in the Elementor panel.
29: *
30: * @since 3.6.0 New: Elementor widgets (beta).
31: */
32: public function get_title() {
33: return esc_html__( 'Pagination', 'easy-property-listings' );
34: }
35:
36: /**
37: * Widget icon.
38: *
39: * @since 3.6.0 New: Elementor widgets (beta).
40: */
41: public function get_icon() {
42: return 'eicon-post-navigation';
43: }
44:
45: /**
46: * Widget categories.
47: *
48: * @since 3.6.0 New: Elementor widgets (beta).
49: */
50: public function get_categories() {
51: return array( 'epl-archive' );
52: }
53:
54: /**
55: * Search keywords for the Elementor panel.
56: *
57: * @since 3.6.0 New: Elementor widgets (beta).
58: */
59: public function get_keywords() {
60: return array( 'epl', 'pagination', 'archive', 'listings', 'next', 'previous' );
61: }
62:
63: /**
64: * Register the widget controls.
65: *
66: * @since 3.6.0 New: Elementor widgets (beta).
67: */
68: protected function register_controls() {
69: $this->start_controls_section( 'section_pagination', array( 'label' => esc_html__( 'Pagination', 'easy-property-listings' ) ) );
70: $this->add_control(
71: 'pagination_style',
72: array(
73: 'label' => esc_html__( 'Pagination Type', 'easy-property-listings' ),
74: 'type' => \Elementor\Controls_Manager::SELECT,
75: 'default' => 'default',
76: 'options' => array(
77: 'fancy' => esc_html__( 'Fancy', 'easy-property-listings' ),
78: 'default' => esc_html__( 'WordPress Default', 'easy-property-listings' ),
79: ),
80: )
81: );
82: $this->add_control(
83: 'editor_note',
84: array(
85: 'type' => \Elementor\Controls_Manager::RAW_HTML,
86: 'raw' => esc_html__( 'Pages the current archive. With Loop Grid, turn off its own pagination.', 'easy-property-listings' ),
87: 'content_classes' => 'elementor-panel-alert elementor-panel-alert-info',
88: )
89: );
90: $this->end_controls_section();
91:
92: $this->start_controls_section( 'section_style', array( 'label' => esc_html__( 'Pagination', 'easy-property-listings' ), 'tab' => \Elementor\Controls_Manager::TAB_STYLE ) );
93: $this->add_responsive_control(
94: 'align',
95: array(
96: 'label' => esc_html__( 'Alignment', 'easy-property-listings' ),
97: 'type' => \Elementor\Controls_Manager::CHOOSE,
98: 'options' => array(
99: 'left' => array( 'title' => esc_html__( 'Left', 'easy-property-listings' ), 'icon' => 'eicon-text-align-left' ),
100: 'center' => array( 'title' => esc_html__( 'Center', 'easy-property-listings' ), 'icon' => 'eicon-text-align-center' ),
101: 'right' => array( 'title' => esc_html__( 'Right', 'easy-property-listings' ), 'icon' => 'eicon-text-align-right' ),
102: ),
103: 'default' => 'center',
104: 'selectors' => array( '{{WRAPPER}}' => 'text-align: {{VALUE}};' ),
105: )
106: );
107: $this->add_group_control( \Elementor\Group_Control_Typography::get_type(), array( 'name' => 'typography', 'selector' => '{{WRAPPER}} .epl-pagination a, {{WRAPPER}} .epl-pagination span, {{WRAPPER}} .epl-paginate-default-wrapper a' ) );
108: $this->end_controls_section();
109: }
110:
111: /**
112: * Render the widget output.
113: *
114: * @since 3.6.0 New: Elementor widgets (beta).
115: */
116: protected function render() {
117: global $wp_query;
118: $loop_context = EPL_Elementor::instance()->get_last_loop_grid_query();
119: $query = ! empty( $loop_context['query'] ) && $loop_context['query'] instanceof WP_Query ? $loop_context['query'] : ( $wp_query instanceof WP_Query ? $wp_query : null );
120: $style = $this->get_settings_for_display( 'pagination_style' );
121: $style = $style ? $style : 'default';
122: if ( ! $query || $query->max_num_pages < 2 ) {
123: if ( EPL_Elementor::is_editor() ) {
124: if ( 'fancy' === $style ) {
125: echo '<div class="wp-pagenavi epl-pagination epl-block-pagination-preview" role="navigation"><span class="pages">' . esc_html__( 'Page 1 of 3', 'easy-property-listings' ) . '</span><span class="current">1</span><a class="page larger">2</a><a class="page larger">3</a><a class="nextpostslink">' . esc_html__( 'Next', 'easy-property-listings' ) . '</a></div>';
126: } else {
127: echo '<div class="epl-paginate-default-wrapper epl-clearfix epl-elementor-pagination-preview"><div class="alignleft">' . esc_html__( 'Previous Page', 'easy-property-listings' ) . '</div><div class="alignright">' . esc_html__( 'Next Page', 'easy-property-listings' ) . '</div></div>';
128: }
129: }
130: return;
131: }
132:
133: if ( ! empty( $loop_context['widget_id'] ) ) {
134: EPL_Elementor::render_loop_grid_epl_navigation( $query, $loop_context['widget_id'], $style );
135: return;
136: }
137: EPL_Elementor::render_epl_pagination( $query, $style );
138: }
139: }
140: