| 1 |
<?php |
| 2 |
namespace Easyel\EasyElements\Widgets; |
| 3 |
use Elementor\Widget_Base; |
| 4 |
use Elementor\Controls_Manager; |
| 5 |
use Elementor\Group_Control_Typography; |
| 6 |
use Elementor\Group_Control_Border; |
| 7 |
use Elementor\Group_Control_Box_Shadow; |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; |
| 11 |
} |
| 12 |
|
| 13 |
class Easyel_Free_Post_Pagination_Widget extends \Elementor\Widget_Base { |
| 14 |
|
| 15 |
|
| 16 |
public function get_name() { |
| 17 |
return 'eel-post-pagination'; |
| 18 |
} |
| 19 |
|
| 20 |
public function get_title() { |
| 21 |
return __( 'Post Pagination', 'easy-elements' ); |
| 22 |
} |
| 23 |
|
| 24 |
public function get_icon() { |
| 25 |
return 'easyicon easyelIcon-pagination'; |
| 26 |
} |
| 27 |
|
| 28 |
public function get_categories() { |
| 29 |
return [ 'easyelements_category' ]; |
| 30 |
} |
| 31 |
|
| 32 |
public function get_keywords() { |
| 33 |
return [ 'pagination', 'posts', 'next', 'prev', 'page', 'blog' ]; |
| 34 |
} |
| 35 |
|
| 36 |
public function get_style_depends() { |
| 37 |
return [ |
| 38 |
'eel-post-pagination', |
| 39 |
]; |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
protected function register_controls() { |
| 44 |
// Content Tab |
| 45 |
$this->start_controls_section( |
| 46 |
'pagination_content', |
| 47 |
[ |
| 48 |
'label' => __( 'Pagination', 'easy-elements' ), |
| 49 |
'tab' => Controls_Manager::TAB_CONTENT, |
| 50 |
] |
| 51 |
); |
| 52 |
|
| 53 |
$this->add_control( |
| 54 |
'show_prev_next', |
| 55 |
[ |
| 56 |
'label' => __( 'Show Prev/Next', 'easy-elements' ), |
| 57 |
'type' => Controls_Manager::SWITCHER, |
| 58 |
'label_on' => __( 'Yes', 'easy-elements' ), |
| 59 |
'label_off' => __( 'No', 'easy-elements' ), |
| 60 |
'default' => 'yes', |
| 61 |
] |
| 62 |
); |
| 63 |
|
| 64 |
$this->add_control( |
| 65 |
'prev_label', |
| 66 |
[ |
| 67 |
'label' => __( 'Previous Label', 'easy-elements' ), |
| 68 |
'type' => Controls_Manager::TEXT, |
| 69 |
'default' => __( 'Previous', 'easy-elements' ), |
| 70 |
'condition' => [ 'show_prev_next' => 'yes' ], |
| 71 |
] |
| 72 |
); |
| 73 |
|
| 74 |
$this->add_control( |
| 75 |
'next_label', |
| 76 |
[ |
| 77 |
'label' => __( 'Next Label', 'easy-elements' ), |
| 78 |
'type' => Controls_Manager::TEXT, |
| 79 |
'default' => __( 'Next', 'easy-elements' ), |
| 80 |
'condition' => [ 'show_prev_next' => 'yes' ], |
| 81 |
] |
| 82 |
); |
| 83 |
|
| 84 |
$this->end_controls_section(); |
| 85 |
|
| 86 |
// Style Tab |
| 87 |
$this->start_controls_section( |
| 88 |
'pagination_style', |
| 89 |
[ |
| 90 |
'label' => __( 'Pagination', 'easy-elements' ), |
| 91 |
'tab' => Controls_Manager::TAB_STYLE, |
| 92 |
] |
| 93 |
); |
| 94 |
|
| 95 |
$this->add_control( |
| 96 |
'pagination_color', |
| 97 |
[ |
| 98 |
'label' => __( 'Label Color', 'easy-elements' ), |
| 99 |
'type' => Controls_Manager::COLOR, |
| 100 |
'selectors' => [ |
| 101 |
'{{WRAPPER}} .eel-nav-label' => 'color: {{VALUE}};', |
| 102 |
], |
| 103 |
] |
| 104 |
); |
| 105 |
|
| 106 |
$this->add_group_control( |
| 107 |
Group_Control_Typography::get_type(), |
| 108 |
[ |
| 109 |
'name' => 'label_typography', |
| 110 |
'label' => __( 'Label Typography', 'easy-elements' ), |
| 111 |
'selector' => '{{WRAPPER}} .eel-nav-label, {{WRAPPER}} .eel-nav-label i', |
| 112 |
] |
| 113 |
); |
| 114 |
|
| 115 |
|
| 116 |
$this->add_control( |
| 117 |
'title_color', |
| 118 |
[ |
| 119 |
'label' => __( 'Title Color', 'easy-elements' ), |
| 120 |
'type' => Controls_Manager::COLOR, |
| 121 |
'selectors' => [ |
| 122 |
'{{WRAPPER}} .eel-nav-title' => 'color: {{VALUE}};', |
| 123 |
], |
| 124 |
] |
| 125 |
); |
| 126 |
|
| 127 |
$this->add_group_control( |
| 128 |
Group_Control_Typography::get_type(), |
| 129 |
[ |
| 130 |
'name' => 'title_typography', |
| 131 |
'label' => __( 'Title Typography', 'easy-elements' ), |
| 132 |
'selector' => '{{WRAPPER}} .eel-nav-title', |
| 133 |
] |
| 134 |
); |
| 135 |
$this->end_controls_section(); |
| 136 |
} |
| 137 |
|
| 138 |
protected function render() { |
| 139 |
$settings = $this->get_settings_for_display(); |
| 140 |
|
| 141 |
// Get the proper post ID (editor or frontend) |
| 142 |
$post_id = function_exists('easyel_get_prepared_post_id') |
| 143 |
? easyel_get_prepared_post_id() |
| 144 |
: get_the_ID(); |
| 145 |
|
| 146 |
if ( ! $post_id ) { |
| 147 |
return; // No post to show |
| 148 |
} |
| 149 |
|
| 150 |
$post_obj = get_post( $post_id ); |
| 151 |
if ( ! $post_obj instanceof \WP_Post ) { |
| 152 |
return; |
| 153 |
} |
| 154 |
|
| 155 |
global $post; |
| 156 |
$original_post = $post; |
| 157 |
$post = $post_obj; |
| 158 |
setup_postdata( $post ); |
| 159 |
|
| 160 |
echo '<nav class="eel-pagination" aria-label="Post Navigation"><ul>'; |
| 161 |
|
| 162 |
if ( ($settings['show_prev_next'] ?? '') === 'yes' ) { |
| 163 |
|
| 164 |
// Previous post link |
| 165 |
$prev = get_previous_post_link( |
| 166 |
'<li>%link</li>', |
| 167 |
'<span class="eel-nav-label"><i class="unicon-arrow-left"></i> ' |
| 168 |
. esc_html( $settings['prev_label'] ?? 'Previous' ) |
| 169 |
. '</span><span class="eel-nav-title">%title</span>' |
| 170 |
); |
| 171 |
|
| 172 |
// Next post link |
| 173 |
$next = get_next_post_link( |
| 174 |
'<li>%link</li>', |
| 175 |
'<span class="eel-nav-label">' |
| 176 |
. esc_html( $settings['next_label'] ?? 'Next' ) |
| 177 |
. ' <i class="unicon-arrow-right"></i></span><span class="eel-nav-title">%title</span>' |
| 178 |
); |
| 179 |
|
| 180 |
if ( $prev ) echo wp_kses_post( $prev ); |
| 181 |
if ( $next ) echo wp_kses_post( $next ); |
| 182 |
} |
| 183 |
|
| 184 |
echo '</ul></nav>'; |
| 185 |
|
| 186 |
wp_reset_postdata(); |
| 187 |
$post = $original_post; |
| 188 |
} |
| 189 |
} |