PluginProbe
Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets / 4.0.9
Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets v4.0.9
4.5.4 4.2.1 4.2.2 4.2.3 4.5.0 4.5.2 4.5.3 4.2.0 4.1.18 4.1.17 4.1.16 4.1.15 4.1.14 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.0.9 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 All 146 releases
ultimate-post-kit / modules / post-category / widgets / post-category.php

post-category.php in Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets 4.0.9, at modules/post-category/widgets/post-category.php

931 lines 24.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace UltimatePostKit\Modules\PostCategory\Widgets;
4
5 use UltimatePostKit\Base\Module_Base;
6 use Elementor\Controls_Manager;
7 use Elementor\Group_Control_Border;
8 use Elementor\Group_Control_Box_Shadow;
9 use Elementor\Group_Control_Typography;
10 use Elementor\Group_Control_Background;
11 use Elementor\Group_Control_Image_Size;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 } // Exit if accessed directly
16
17 class Post_Category extends Module_Base {
18 private $_query = null;
19
20 public function get_name() {
21 return 'upk-post-category';
22 }
23
24 public function get_title() {
25 return BDTUPK . esc_html__( 'Category', 'ultimate-post-kit' );
26 }
27
28 public function get_icon() {
29 return 'upk-widget-icon upk-icon-post-category';
30 }
31
32 public function get_categories() {
33 return [ 'ultimate-post-kit' ];
34 }
35
36 public function get_keywords() {
37 return [ 'post', 'list', 'blog', 'recent', 'news', 'category' ];
38 }
39
40 public function get_style_depends() {
41 if ( $this->upk_is_edit_mode() ) {
42 return [ 'upk-all-styles' ];
43 } else {
44 return [ 'upk-post-category' ];
45 }
46 }
47
48 public function get_custom_help_url() {
49 return 'https://youtu.be/3S5hRqxTDTo';
50 }
51
52 public function get_query() {
53 return $this->_query;
54 }
55
56 public function has_widget_inner_wrapper(): bool {
57 return ! \Elementor\Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' );
58 }
59
60
61 protected function register_controls() {
62
63 $image_settings = ultimate_post_kit_option( 'category_image', 'ultimate_post_kit_other_settings', 'off' );
64
65 $this->start_controls_section(
66 'section_content_layout',
67 [
68 'label' => esc_html__( 'Layout', 'ultimate-post-kit' ),
69 ]
70 );
71
72 $this->add_control(
73 'style',
74 [
75 'label' => __( 'Style', 'ultimate-post-kit' ),
76 'type' => Controls_Manager::SELECT,
77 'default' => '1',
78 'options' => [
79 '1' => 'Style 1',
80 '2' => 'Style 2',
81 ],
82 ]
83 );
84
85 $this->add_responsive_control(
86 'columns',
87 [
88 'label' => __( 'Columns', 'ultimate-post-kit' ),
89 'type' => Controls_Manager::SELECT,
90 'default' => '3',
91 'tablet_default' => '2',
92 'mobile_default' => '1',
93 'options' => [
94 '1' => '1',
95 '2' => '2',
96 '3' => '3',
97 '4' => '4',
98 '5' => '5',
99 '6' => '6',
100 ],
101 'selectors' => [
102 '{{WRAPPER}} .upk-post-category' => 'grid-template-columns: repeat({{SIZE}}, 1fr);',
103 ],
104 ]
105 );
106
107 $this->add_responsive_control(
108 'column_gap',
109 [
110 'label' => esc_html__( 'Column Gap', 'ultimate-post-kit' ),
111 'type' => Controls_Manager::SLIDER,
112 'default' => [
113 'size' => 20,
114 ],
115 'selectors' => [
116 '{{WRAPPER}} .upk-post-category' => 'grid-gap: {{SIZE}}{{UNIT}};',
117 ],
118 ]
119 );
120
121 $this->add_responsive_control(
122 'item_height',
123 [
124 'label' => esc_html__( 'Item Height', 'ultimate-post-kit' ),
125 'type' => Controls_Manager::SLIDER,
126 'range' => [
127 'px' => [
128 'min' => 50,
129 'max' => 500,
130 ],
131 ],
132 'selectors' => [
133 '{{WRAPPER}} .upk-post-category .upk-category-item' => 'min-height: {{SIZE}}{{UNIT}};',
134 ],
135 ]
136 );
137
138 $this->add_responsive_control(
139 'alignment',
140 [
141 'label' => __( 'Alignment', 'ultimate-post-kit' ),
142 'type' => Controls_Manager::CHOOSE,
143 'options' => [
144 'left' => [
145 'title' => __( 'Left', 'ultimate-post-kit' ),
146 'icon' => 'eicon-text-align-left',
147 ],
148 'center' => [
149 'title' => __( 'Center', 'ultimate-post-kit' ),
150 'icon' => 'eicon-text-align-center',
151 ],
152 'right' => [
153 'title' => __( 'Right', 'ultimate-post-kit' ),
154 'icon' => 'eicon-text-align-right',
155 ]
156 ],
157 'selectors' => [
158 '{{WRAPPER}} .upk-post-category .upk-category-item' => 'text-align: {{VALUE}};',
159 ],
160 ]
161 );
162 if ( $image_settings == 'on' ) :
163 $this->add_control(
164 'show_image',
165 [
166 'label' => esc_html__( 'Show Image', 'ultimate-post-kit' ),
167 'type' => Controls_Manager::SWITCHER,
168 'default' => 'no',
169 'separator' => 'before'
170 ]
171 );
172 endif;
173 $this->add_group_control(
174 Group_Control_Image_Size::get_type(),
175 [
176 'name' => 'cat_image_size',
177 'exclude' => [ 'custom' ],
178 'include' => [],
179 'default' => 'thumbnail',
180 'condition' => [
181 'show_image' => 'yes'
182 ]
183 ]
184 );
185 $this->add_control(
186 'show_count',
187 [
188 'label' => esc_html__( 'Show Count', 'ultimate-post-kit' ),
189 'type' => Controls_Manager::SWITCHER,
190 'default' => 'yes',
191 ]
192 );
193
194 $this->add_control(
195 'show_text',
196 [
197 'label' => esc_html__( 'Show Text', 'ultimate-post-kit' ),
198 'type' => Controls_Manager::SWITCHER,
199 ]
200 );
201
202 $this->add_control(
203 'text_length',
204 [
205 'label' => esc_html__( 'Text Limit', 'ultimate-post-kit' ),
206 'description' => esc_html__( 'If you set 0 so you will get full main content.', 'ultimate-post-kit' ),
207 'type' => Controls_Manager::NUMBER,
208 'default' => 30,
209 'condition' => [
210 'show_text' => 'yes'
211 ],
212 ]
213 );
214
215 $this->add_control(
216 'view_all_button',
217 [
218 'label' => esc_html__( 'View All Button', 'ultimate-post-kit' ),
219 'type' => Controls_Manager::SWITCHER,
220 ]
221 );
222
223 $this->end_controls_section();
224
225 $this->start_controls_section(
226 'section_post_grid_query',
227 [
228 'label' => esc_html__( 'Query', 'ultimate-post-kit' ),
229 ]
230 );
231
232 $this->add_control(
233 'item_limit',
234 [
235 'label' => esc_html__( 'Item Limit', 'ultimate-post-kit' ),
236 'type' => Controls_Manager::SLIDER,
237 'range' => [
238 'px' => [
239 'min' => 1,
240 'max' => 50,
241 ],
242 ],
243 'default' => [
244 'size' => 6,
245 ],
246 ]
247 );
248
249 $this->add_control(
250 'taxonomy',
251 [
252 'label' => esc_html__( 'Taxonomy', 'ultimate-post-kit' ),
253 'type' => Controls_Manager::SELECT,
254 'default' => 'category',
255 'options' => ultimate_post_kit_get_taxonomies(),
256 ]
257 );
258
259 $this->add_control(
260 'orderby',
261 [
262 'label' => esc_html__( 'Order By', 'ultimate-post-kit' ),
263 'type' => Controls_Manager::SELECT,
264 'default' => 'name',
265 'options' => [
266 'name' => esc_html__( 'Name', 'ultimate-post-kit' ),
267 'post_date' => esc_html__( 'Date', 'ultimate-post-kit' ),
268 'post_title' => esc_html__( 'Title', 'ultimate-post-kit' ),
269 'menu_order' => esc_html__( 'Menu Order', 'ultimate-post-kit' ),
270 'rand' => esc_html__( 'Random', 'ultimate-post-kit' ),
271 ],
272 ]
273 );
274
275 $this->add_control(
276 'order',
277 [
278 'label' => esc_html__( 'Order', 'ultimate-post-kit' ),
279 'type' => Controls_Manager::SELECT,
280 'default' => 'asc',
281 'options' => [
282 'asc' => esc_html__( 'ASC', 'ultimate-post-kit' ),
283 'desc' => esc_html__( 'DESC', 'ultimate-post-kit' ),
284 ],
285 ]
286 );
287
288 $this->add_control(
289 'exclude',
290 [
291 'label' => esc_html__( 'Exclude', 'ultimate-post-kit' ),
292 'type' => Controls_Manager::TEXT,
293 'placeholder' => __( 'Category ID: 12,3,1', 'ultimate-post-kit' ),
294 ]
295 );
296
297 $this->add_control(
298 'parent',
299 [
300 'label' => esc_html__( 'Parent', 'ultimate-post-kit' ),
301 'type' => Controls_Manager::TEXT,
302 'placeholder' => __( 'Category ID: 12', 'ultimate-post-kit' ),
303 ]
304 );
305
306 $this->end_controls_section();
307
308 //Style
309 $this->start_controls_section(
310 'upk_section_style',
311 [
312 'label' => esc_html__( 'Items', 'ultimate-post-kit' ),
313 'tab' => Controls_Manager::TAB_STYLE,
314 ]
315 );
316
317 $this->start_controls_tabs( 'tabs_item_style' );
318
319 $this->start_controls_tab(
320 'tab_item_normal',
321 [
322 'label' => esc_html__( 'Normal', 'ultimate-post-kit' ),
323 ]
324 );
325
326 $this->add_control(
327 'single_background',
328 [
329 'label' => esc_html__( 'Single Background', 'ultimate-post-kit' ),
330 'type' => Controls_Manager::SWITCHER,
331 ]
332 );
333
334 $this->add_group_control(
335 Group_Control_Background::get_type(),
336 [
337 'name' => 'item_background',
338 'selector' => '{{WRAPPER}} .upk-post-category .upk-category-item',
339 'condition' => [
340 'single_background' => 'yes'
341 ]
342 ]
343 );
344
345 $this->add_control(
346 'multiple_background',
347 [
348 'label' => esc_html__( 'Multiple Background', 'ultimate-post-kit' ),
349 'type' => Controls_Manager::TEXTAREA,
350 'placeholder' => '#000000, #f5f5f5, #999999',
351 'condition' => [
352 'single_background' => ''
353 ]
354 ]
355 );
356
357 $this->add_group_control(
358 Group_Control_Border::get_type(),
359 [
360 'name' => 'item_border',
361 'selector' => '{{WRAPPER}} .upk-post-category .upk-category-item',
362 ]
363 );
364
365 $this->add_responsive_control(
366 'item_border_radius',
367 [
368 'label' => esc_html__( 'Border Radius', 'ultimate-post-kit' ),
369 'type' => Controls_Manager::DIMENSIONS,
370 'size_units' => [ 'px', '%' ],
371 'selectors' => [
372 '{{WRAPPER}} .upk-post-category .upk-category-item' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
373 ],
374 ]
375 );
376
377 $this->add_responsive_control(
378 'item_padding',
379 [
380 'label' => __( 'Padding', 'ultimate-post-kit' ),
381 'type' => Controls_Manager::DIMENSIONS,
382 'size_units' => [ 'px', 'em', '%' ],
383 'selectors' => [
384 '{{WRAPPER}} .upk-post-category .upk-category-item' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
385 ],
386 ]
387 );
388
389 $this->add_group_control(
390 Group_Control_Box_Shadow::get_type(),
391 [
392 'name' => 'item_box_shadow',
393 'selector' => '{{WRAPPER}} .upk-post-category .upk-category-item',
394 ]
395 );
396
397 $this->end_controls_tab();
398
399 $this->start_controls_tab(
400 'tab_item_hover',
401 [
402 'label' => esc_html__( 'Hover', 'ultimate-post-kit' ),
403 ]
404 );
405
406 $this->add_group_control(
407 Group_Control_Background::get_type(),
408 [
409 'name' => 'itam_background_hover',
410 'selector' => '{{WRAPPER}} .upk-post-category .upk-category-item:hover',
411 ]
412 );
413
414 $this->add_control(
415 'item_border_color_hover',
416 [
417 'label' => esc_html__( 'Border Color', 'ultimate-post-kit' ),
418 'type' => Controls_Manager::COLOR,
419 'selectors' => [
420 '{{WRAPPER}} .upk-post-category .upk-category-item:hover' => 'border-color: {{VALUE}};'
421 ],
422 'condition' => [
423 'item_border_border!' => ''
424 ]
425 ]
426 );
427
428 $this->add_group_control(
429 Group_Control_Box_Shadow::get_type(),
430 [
431 'name' => 'item_box_shadow_hover',
432 'selector' => '{{WRAPPER}} .upk-post-category .upk-category-item:hover',
433 ]
434 );
435
436 $this->add_control(
437 'item_hover_opacity',
438 [
439 'label' => esc_html__( 'Opacity', 'ultimate-post-kit' ),
440 'type' => Controls_Manager::SLIDER,
441 'range' => [
442 'px' => [
443 'min' => 0,
444 'max' => 1,
445 'step' => 0.1
446 ],
447 ],
448 'selectors' => [
449 '{{WRAPPER}} .upk-post-category .upk-category-item:hover' => 'opacity: {{SIZE}};',
450 ],
451 ]
452 );
453
454 $this->end_controls_tab();
455
456 $this->end_controls_tabs();
457
458 $this->end_controls_section();
459
460 $this->start_controls_section(
461 'section_style_category_image',
462 [
463 'label' => esc_html__( 'Image', 'ultimate-post-kit' ),
464 'tab' => Controls_Manager::TAB_STYLE,
465 'condition' => [
466 'show_image' => 'yes',
467 ]
468 ]
469 );
470
471 $this->add_group_control(
472 Group_Control_Background::get_type(),
473 [
474 'name' => 'cat_image_background',
475 'selector' => '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-image img',
476 ]
477 );
478 $this->add_responsive_control(
479 'cat_image_width',
480 [
481 'label' => esc_html__( 'Image Size', 'ultimate-post-kit' ),
482 'type' => Controls_Manager::SLIDER,
483 'size_units' => [ '%' ],
484 'default' => [
485 'unit' => '%',
486 'size' => 100,
487 ],
488 'selectors' => [
489 '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-image img' => 'width: {{SIZE}}{{UNIT}};',
490 ],
491 'condition' => [
492 'style' => '1'
493 ]
494 ]
495 );
496 $this->add_group_control(
497 Group_Control_Border::get_type(),
498 [
499 'name' => 'cat_image_border',
500 'label' => esc_html__( 'Border', 'ultimate-post-kit' ),
501 'selector' => '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-image img',
502 ]
503 );
504
505 $this->add_responsive_control(
506 'cat_image_radius',
507 [
508 'label' => esc_html__( 'Border Radius', 'ultimate-post-kit' ),
509 'type' => Controls_Manager::DIMENSIONS,
510 'size_units' => [ 'px', '%', 'em' ],
511 'selectors' => [
512 '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-image img' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
513 ],
514 ]
515 );
516
517 $this->add_responsive_control(
518 'cat_image_padding',
519 [
520 'label' => esc_html__( 'Padding', 'ultimate-post-kit' ),
521 'type' => Controls_Manager::DIMENSIONS,
522 'size_units' => [ 'px', '%', 'em' ],
523 'selectors' => [
524 '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-image img' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
525 ],
526 ]
527 );
528 $this->add_responsive_control(
529 'cat_image_bottom_spacing',
530 [
531 'label' => esc_html__( 'Spacing', 'ultimate-post-kit' ),
532 'type' => Controls_Manager::SLIDER,
533 'default' => [
534 'unit' => 'px',
535 'size' => 10,
536 ],
537 'selectors' => [
538 '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-image' => 'margin-bottom: {{SIZE}}{{UNIT}};',
539 ],
540 'condition' => [
541 'style' => '1'
542 ],
543 ]
544 );
545
546
547 $this->add_group_control(
548 Group_Control_Box_Shadow::get_type(),
549 [
550 'name' => 'cat_image_box_shadow',
551 'label' => esc_html__( 'Shadow', 'ultimate-post-kit' ),
552 'selector' => '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-image img',
553 ]
554 );
555
556 $this->end_controls_section();
557
558 $this->start_controls_section(
559 'section_style_category_name',
560 [
561 'label' => esc_html__( 'Name', 'ultimate-post-kit' ),
562 'tab' => Controls_Manager::TAB_STYLE,
563 ]
564 );
565
566 $this->add_control(
567 'category_name_color',
568 [
569 'label' => esc_html__( 'Color', 'ultimate-post-kit' ),
570 'type' => Controls_Manager::COLOR,
571 'selectors' => [
572 '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-name' => 'color: {{VALUE}};',
573 ],
574 ]
575 );
576
577 $this->add_control(
578 'category_name_color_hover',
579 [
580 'label' => esc_html__( 'Hover Color', 'ultimate-post-kit' ),
581 'type' => Controls_Manager::COLOR,
582 'selectors' => [
583 '{{WRAPPER}} .upk-post-category .upk-category-item:hover .upk-category-name' => 'color: {{VALUE}};',
584 ],
585 ]
586 );
587
588 $this->add_group_control(
589 Group_Control_Typography::get_type(),
590 [
591 'name' => 'category_name_typography',
592 'label' => esc_html__( 'Typography', 'ultimate-post-kit' ),
593 'selector' => '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-name',
594 ]
595 );
596
597 $this->end_controls_section();
598
599 $this->start_controls_section(
600 'section_style_category_text',
601 [
602 'label' => esc_html__( 'Description', 'ultimate-post-kit' ),
603 'tab' => Controls_Manager::TAB_STYLE,
604 ]
605 );
606
607 $this->add_control(
608 'category_text_color',
609 [
610 'label' => esc_html__( 'Color', 'ultimate-post-kit' ),
611 'type' => Controls_Manager::COLOR,
612 'selectors' => [
613 '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-text' => 'color: {{VALUE}};',
614 ],
615 ]
616 );
617
618 $this->add_control(
619 'category_text_color_hover',
620 [
621 'label' => esc_html__( 'Hover Color', 'ultimate-post-kit' ),
622 'type' => Controls_Manager::COLOR,
623 'selectors' => [
624 '{{WRAPPER}} .upk-post-category .upk-category-item:hover .upk-category-text' => 'color: {{VALUE}};',
625 ],
626 ]
627 );
628
629 $this->add_responsive_control(
630 'category_text_spacing',
631 [
632 'label' => __( 'Spacing', 'ultimate-post-kit' ),
633 'type' => Controls_Manager::SLIDER,
634 'range' => [
635 'px' => [
636 'min' => 0,
637 'max' => 50,
638 ],
639 ],
640 'selectors' => [
641 '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-text' => 'padding-top: {{SIZE}}px;'
642 ],
643 ]
644 );
645
646 $this->add_group_control(
647 Group_Control_Typography::get_type(),
648 [
649 'name' => 'category_text_typography',
650 'label' => esc_html__( 'Typography', 'ultimate-post-kit' ),
651 'selector' => '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-text',
652 ]
653 );
654
655 $this->end_controls_section();
656
657 $this->start_controls_section(
658 'section_style_count',
659 [
660 'label' => esc_html__( 'Count', 'ultimate-post-kit' ),
661 'tab' => Controls_Manager::TAB_STYLE,
662 ]
663 );
664
665 $this->add_control(
666 'count_color',
667 [
668 'label' => esc_html__( 'Color', 'ultimate-post-kit' ),
669 'type' => Controls_Manager::COLOR,
670 'selectors' => [
671 '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-count' => 'color: {{VALUE}};',
672 ],
673 ]
674 );
675
676 $this->add_control(
677 'count_color_hover',
678 [
679 'label' => esc_html__( 'Hover Color', 'ultimate-post-kit' ),
680 'type' => Controls_Manager::COLOR,
681 'selectors' => [
682 '{{WRAPPER}} .upk-post-category .upk-category-item:hover .upk-category-count' => 'color: {{VALUE}};',
683 ],
684 ]
685 );
686
687 $this->add_group_control(
688 Group_Control_Background::get_type(),
689 [
690 'name' => 'count_background',
691 'selector' => '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-count',
692 ]
693 );
694
695 $this->add_group_control(
696 Group_Control_Border::get_type(),
697 [
698 'name' => 'count_border',
699 'selector' => '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-count',
700 ]
701 );
702
703 $this->add_responsive_control(
704 'count_border_radius',
705 [
706 'label' => esc_html__( 'Border Radius', 'ultimate-post-kit' ),
707 'type' => Controls_Manager::DIMENSIONS,
708 'size_units' => [ 'px', '%' ],
709 'selectors' => [
710 '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-count' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
711 ],
712 ]
713 );
714
715 $this->add_responsive_control(
716 'count_padding',
717 [
718 'label' => __( 'Padding', 'ultimate-post-kit' ),
719 'type' => Controls_Manager::DIMENSIONS,
720 'size_units' => [ 'px', 'em', '%' ],
721 'selectors' => [
722 '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-count' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
723 ],
724 ]
725 );
726
727 $this->add_group_control(
728 Group_Control_Box_Shadow::get_type(),
729 [
730 'name' => 'count_box_shadow',
731 'selector' => '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-count',
732 ]
733 );
734
735 $this->add_group_control(
736 Group_Control_Typography::get_type(),
737 [
738 'name' => 'count_typography',
739 'label' => esc_html__( 'Typography', 'ultimate-post-kit' ),
740 'selector' => '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-count',
741 ]
742 );
743
744 $this->add_control(
745 'count_offset_toggle',
746 [
747 'label' => __( 'Offset', 'ultimate-post-kit' ),
748 'type' => Controls_Manager::POPOVER_TOGGLE,
749 'label_off' => __( 'None', 'ultimate-post-kit' ),
750 'label_on' => __( 'Custom', 'ultimate-post-kit' ),
751 'return_value' => 'yes',
752 ]
753 );
754
755 $this->start_popover();
756
757 $this->add_responsive_control(
758 'count_horizontal_offset',
759 [
760 'label' => __( 'Horizontal Offset', 'ultimate-post-kit' ),
761 'type' => Controls_Manager::SLIDER,
762 'range' => [
763 'px' => [
764 'min' => -300,
765 'step' => 2,
766 'max' => 300,
767 ],
768 ],
769 'condition' => [
770 'count_offset_toggle' => 'yes'
771 ],
772 'render_type' => 'ui',
773 'selectors' => [
774 '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-count' => 'right: {{SIZE}}px;',
775 ],
776 ]
777 );
778
779 $this->add_responsive_control(
780 'count_vertical_offset',
781 [
782 'label' => __( 'Vertical Offset', 'ultimate-post-kit' ),
783 'type' => Controls_Manager::SLIDER,
784 'range' => [
785 'px' => [
786 'min' => -300,
787 'step' => 2,
788 'max' => 300,
789 ],
790 ],
791 'condition' => [
792 'count_offset_toggle' => 'yes'
793 ],
794 'render_type' => 'ui',
795 'selectors' => [
796 '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-count' => 'top: {{SIZE}}px;',
797 ],
798 ]
799 );
800
801 $this->end_popover();
802
803 $this->end_controls_section();
804 }
805
806 public function render() {
807 $settings = $this->get_settings_for_display();
808 $image_settings = ultimate_post_kit_option( 'category_image', 'ultimate_post_kit_other_settings', 'off' );
809 $categories = get_categories(
810 [
811 'taxonomy' => $settings["taxonomy"],
812 'orderby' => $settings["orderby"],
813 'order' => $settings["order"],
814 'hide_empty' => 0,
815 'exclude' => explode( ',', esc_attr( $settings["exclude"] ) ),
816 'parent' => $settings["parent"],
817 ]
818 );
819
820 $this->add_render_attribute( 'category-container', 'class', 'upk-post-category' );
821 $this->add_render_attribute( 'category-container', 'class', 'upk-category-style-' . $settings['style'] );
822
823 if ( $settings['view_all_button'] == 'yes' ) {
824 $this->add_render_attribute( 'category-container', 'class', 'upk-category-view-all' );
825 }
826
827
828 if ( ! empty( $categories ) ) :
829
830 ?>
831 <div <?php $this->print_render_attribute_string( 'category-container' ); ?>>
832 <?php
833 $multi_bg = isset( $settings['multiple_background'] ) && ! empty( $settings['multiple_background'] ) ? $settings['multiple_background'] : '';
834 $multiple_bg = explode( ',', rtrim( $multi_bg, ',' ) );
835 $total_category = count( $categories );
836
837 // re-creating array for the multiple colors
838 $jCount = count( $multiple_bg );
839 $j = 0;
840 for ( $i = 0; $i < $total_category; $i++ ) {
841 if ( $j == $jCount ) {
842 $j = 0;
843 }
844 $multiple_bg_create[ $i ] = $multiple_bg[ $j ];
845 $j++;
846 }
847
848 foreach ( $categories as $index => $cat ) :
849
850 $this->add_render_attribute( 'category-item', 'class', 'upk-category-item', true );
851
852 $this->add_render_attribute( 'category-item', 'href', get_category_link( $cat->cat_ID ), true );
853
854 $bg_color = strToHex( $cat->cat_name );
855 //===============================
856 // CATEGORY IMAGE
857 $category_image_id = get_term_meta( $cat->cat_ID, 'upk-category-image-id', true );
858
859 if ( ! empty( $category_image_id ) ) {
860 $category_url = wp_get_attachment_image_url( $category_image_id, $settings['cat_image_size_size'] );
861 $category_image = '<div class="upk-category-image"><img src="' . $category_url . '" alt=""></div>';
862 } else {
863 $category_image = '';
864 }
865 //===============================
866
867 if ( ! empty( $settings['multiple_background'] ) ) {
868 $bg_color = $multiple_bg_create[ $index ];
869 if ( ! preg_match( '/#([a-f]|[A-F]|[0-9]){3}(([a-f]|[A-F]|[0-9]){3})?\b/', $multiple_bg_create[ $index ] ) ) {
870 $bg_color = strToHex( $cat->cat_name );
871 }
872 }
873
874 if ( $settings['single_background'] == '' ) {
875 $this->add_render_attribute( 'category-item', 'style', "background-color: $bg_color", true );
876 }
877
878 ?>
879
880 <a <?php $this->print_render_attribute_string( 'category-item' ); ?>>
881 <!-- display image -->
882 <?php if ( $image_settings == 'on' && $settings['show_image'] == 'yes' ) :
883 echo wp_kses_post($category_image);
884 endif; ?>
885 <div class="upk-content">
886 <span class="upk-category-name">
887 <?php echo esc_html( $cat->cat_name ); ?>
888 </span>
889
890 <?php if ( ! empty( $cat->category_description ) and $settings['show_text'] == 'yes' ) : ?>
891 <span class="upk-category-text">
892 <?php echo wp_trim_words( $cat->category_description, $settings['text_length'] ); ?>
893 </span>
894 <?php endif; ?>
895
896 <?php if ( $settings['show_count'] == 'yes' ) : ?>
897
898 <span class="upk-category-count">
899 <?php echo esc_html( $cat->category_count ); ?>
900 </span>
901 <?php endif; ?>
902 </div>
903
904 <?php if ( $settings['view_all_button'] == 'yes' ) : ?>
905 <div class="upk-category-btn">
906 <span>
907 <?php esc_html_e( 'view all', 'ultimate-post-kit' ); ?>
908 </span>
909 </div>
910 <?php endif; ?>
911
912 </a>
913 <?php
914
915 if ( ! empty( $settings['item_limit']['size'] ) ) {
916 if ( $index == ( $settings['item_limit']['size'] - 1 ) ) {
917 break;
918 }
919 }
920 endforeach;
921 ?>
922 </div>
923 <?php
924 else :
925
926 echo '<div class="upk-alert">' . esc_html__( 'Category Not Found!', 'ultimate-post-kit' ) . '</div>';
927
928 endif;
929 }
930 }
931