PluginProbe
Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets / 4.5.6
Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets v4.5.6
4.5.6 4.5.5 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 All 148 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.5.6, at modules/post-category/widgets/post-category.php

974 lines 26.3 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 // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude -- Elementor widget query built from user-configured controls; expected behaviour.
178 'exclude' => [ 'custom' ],
179 'include' => [],
180 'default' => 'thumbnail',
181 'condition' => [
182 'show_image' => 'yes'
183 ]
184 ]
185 );
186 $this->add_control(
187 'show_count',
188 [
189 'label' => esc_html__( 'Show Count', 'ultimate-post-kit' ),
190 'type' => Controls_Manager::SWITCHER,
191 'default' => 'yes',
192 ]
193 );
194
195 $this->add_control(
196 'show_text',
197 [
198 'label' => esc_html__( 'Show Text', 'ultimate-post-kit' ),
199 'type' => Controls_Manager::SWITCHER,
200 ]
201 );
202
203 $this->add_control(
204 'text_length',
205 [
206 'label' => esc_html__( 'Text Limit', 'ultimate-post-kit' ),
207 'description' => esc_html__( 'If you set 0 so you will get full main content.', 'ultimate-post-kit' ),
208 'type' => Controls_Manager::NUMBER,
209 'default' => 30,
210 'condition' => [
211 'show_text' => 'yes'
212 ],
213 ]
214 );
215
216 $this->add_control(
217 'view_all_button',
218 [
219 'label' => esc_html__( 'View All Button', 'ultimate-post-kit' ),
220 'type' => Controls_Manager::SWITCHER,
221 ]
222 );
223
224 $this->end_controls_section();
225
226 $this->start_controls_section(
227 'section_post_grid_query',
228 [
229 'label' => esc_html__( 'Query', 'ultimate-post-kit' ),
230 ]
231 );
232
233 $this->add_control(
234 'item_limit',
235 [
236 'label' => esc_html__( 'Item Limit', 'ultimate-post-kit' ),
237 'type' => Controls_Manager::SLIDER,
238 'range' => [
239 'px' => [
240 'min' => 1,
241 'max' => 50,
242 ],
243 ],
244 'default' => [
245 'size' => 6,
246 ],
247 'condition' => [
248 'posts_source!' => 'current_query',
249 ]
250 ]
251 );
252
253 $this->add_control(
254 'taxonomy',
255 [
256 'label' => esc_html__( 'Taxonomy', 'ultimate-post-kit' ),
257 'type' => Controls_Manager::SELECT,
258 'default' => 'category',
259 'options' => ultimate_post_kit_get_taxonomies(),
260 ]
261 );
262
263 $this->add_control(
264 'orderby',
265 [
266 'label' => esc_html__( 'Order By', 'ultimate-post-kit' ),
267 'type' => Controls_Manager::SELECT,
268 'default' => 'name',
269 'options' => [
270 'name' => esc_html__( 'Name', 'ultimate-post-kit' ),
271 'term_id' => esc_html__( 'ID', 'ultimate-post-kit' ),
272 'slug' => esc_html__( 'Slug', 'ultimate-post-kit' ),
273 'count' => esc_html__( 'Post Count', 'ultimate-post-kit' ),
274 'description' => esc_html__( 'Description', 'ultimate-post-kit' ),
275 'parent' => esc_html__( 'Parent', 'ultimate-post-kit' ),
276 'term_order' => esc_html__( 'Menu Order', 'ultimate-post-kit' ),
277 'rand' => esc_html__( 'Random', 'ultimate-post-kit' ),
278 ],
279 ]
280 );
281
282 $this->add_control(
283 'minimum_post_count',
284 [
285 'label' => esc_html__( 'Minimum Post Count', 'ultimate-post-kit' ) .BDTUPK_NC,
286 'type' => Controls_Manager::NUMBER,
287 'default' => 0,
288 'min' => 0,
289 'placeholder' => '0',
290 'condition' => [
291 'orderby' => 'count',
292 ],
293 'description' => esc_html__( 'Hide categories that have fewer than this many posts. 0 = show all.', 'ultimate-post-kit' ),
294 ]
295 );
296
297 $this->add_control(
298 'order',
299 [
300 'label' => esc_html__( 'Order', 'ultimate-post-kit' ),
301 'type' => Controls_Manager::SELECT,
302 'default' => 'asc',
303 'options' => [
304 'asc' => esc_html__( 'ASC', 'ultimate-post-kit' ),
305 'desc' => esc_html__( 'DESC', 'ultimate-post-kit' ),
306 ],
307 ]
308 );
309
310 $this->add_control(
311 'exclude',
312 [
313 'label' => esc_html__( 'Exclude', 'ultimate-post-kit' ),
314 'type' => Controls_Manager::TEXT,
315 'placeholder' => __( 'Category ID: 12,3,1', 'ultimate-post-kit' ),
316 ]
317 );
318
319 $this->add_control(
320 'parent',
321 [
322 'label' => esc_html__( 'Parent', 'ultimate-post-kit' ),
323 'type' => Controls_Manager::TEXT,
324 'placeholder' => __( 'Category ID: 12', 'ultimate-post-kit' ),
325 ]
326 );
327
328 $this->end_controls_section();
329
330 //Style
331 $this->start_controls_section(
332 'upk_section_style',
333 [
334 'label' => esc_html__( 'Items', 'ultimate-post-kit' ),
335 'tab' => Controls_Manager::TAB_STYLE,
336 ]
337 );
338
339 $this->start_controls_tabs( 'tabs_item_style' );
340
341 $this->start_controls_tab(
342 'tab_item_normal',
343 [
344 'label' => esc_html__( 'Normal', 'ultimate-post-kit' ),
345 ]
346 );
347
348 $this->add_control(
349 'single_background',
350 [
351 'label' => esc_html__( 'Single Background', 'ultimate-post-kit' ),
352 'type' => Controls_Manager::SWITCHER,
353 ]
354 );
355
356 $this->add_group_control(
357 Group_Control_Background::get_type(),
358 [
359 'name' => 'item_background',
360 'selector' => '{{WRAPPER}} .upk-post-category .upk-category-item',
361 'condition' => [
362 'single_background' => 'yes'
363 ]
364 ]
365 );
366
367 $this->add_control(
368 'multiple_background',
369 [
370 'label' => esc_html__( 'Multiple Background', 'ultimate-post-kit' ),
371 'type' => Controls_Manager::TEXTAREA,
372 'placeholder' => '#000000, #f5f5f5, #999999',
373 'condition' => [
374 'single_background' => ''
375 ]
376 ]
377 );
378
379 $this->add_group_control(
380 Group_Control_Border::get_type(),
381 [
382 'name' => 'item_border',
383 'selector' => '{{WRAPPER}} .upk-post-category .upk-category-item',
384 ]
385 );
386
387 $this->add_responsive_control(
388 'item_border_radius',
389 [
390 'label' => esc_html__( 'Border Radius', 'ultimate-post-kit' ),
391 'type' => Controls_Manager::DIMENSIONS,
392 'size_units' => [ 'px', '%' ],
393 'selectors' => [
394 '{{WRAPPER}} .upk-post-category .upk-category-item' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
395 ],
396 ]
397 );
398
399 $this->add_responsive_control(
400 'item_padding',
401 [
402 'label' => __( 'Padding', 'ultimate-post-kit' ),
403 'type' => Controls_Manager::DIMENSIONS,
404 'size_units' => [ 'px', 'em', '%' ],
405 'selectors' => [
406 '{{WRAPPER}} .upk-post-category .upk-category-item' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
407 ],
408 ]
409 );
410
411 $this->add_group_control(
412 Group_Control_Box_Shadow::get_type(),
413 [
414 'name' => 'item_box_shadow',
415 'selector' => '{{WRAPPER}} .upk-post-category .upk-category-item',
416 ]
417 );
418
419 $this->end_controls_tab();
420
421 $this->start_controls_tab(
422 'tab_item_hover',
423 [
424 'label' => esc_html__( 'Hover', 'ultimate-post-kit' ),
425 ]
426 );
427
428 $this->add_group_control(
429 Group_Control_Background::get_type(),
430 [
431 'name' => 'itam_background_hover',
432 'selector' => '{{WRAPPER}} .upk-post-category .upk-category-item:hover',
433 ]
434 );
435
436 $this->add_control(
437 'item_border_color_hover',
438 [
439 'label' => esc_html__( 'Border Color', 'ultimate-post-kit' ),
440 'type' => Controls_Manager::COLOR,
441 'selectors' => [
442 '{{WRAPPER}} .upk-post-category .upk-category-item:hover' => 'border-color: {{VALUE}};'
443 ],
444 'condition' => [
445 'item_border_border!' => ''
446 ]
447 ]
448 );
449
450 $this->add_group_control(
451 Group_Control_Box_Shadow::get_type(),
452 [
453 'name' => 'item_box_shadow_hover',
454 'selector' => '{{WRAPPER}} .upk-post-category .upk-category-item:hover',
455 ]
456 );
457
458 $this->add_control(
459 'item_hover_opacity',
460 [
461 'label' => esc_html__( 'Opacity', 'ultimate-post-kit' ),
462 'type' => Controls_Manager::SLIDER,
463 'range' => [
464 'px' => [
465 'min' => 0,
466 'max' => 1,
467 'step' => 0.1
468 ],
469 ],
470 'selectors' => [
471 '{{WRAPPER}} .upk-post-category .upk-category-item:hover' => 'opacity: {{SIZE}};',
472 ],
473 ]
474 );
475
476 $this->end_controls_tab();
477
478 $this->end_controls_tabs();
479
480 $this->end_controls_section();
481
482 $this->start_controls_section(
483 'section_style_category_image',
484 [
485 'label' => esc_html__( 'Image', 'ultimate-post-kit' ),
486 'tab' => Controls_Manager::TAB_STYLE,
487 'condition' => [
488 'show_image' => 'yes',
489 ]
490 ]
491 );
492
493 $this->add_group_control(
494 Group_Control_Background::get_type(),
495 [
496 'name' => 'cat_image_background',
497 'selector' => '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-image img',
498 ]
499 );
500 $this->add_responsive_control(
501 'cat_image_width',
502 [
503 'label' => esc_html__( 'Image Size', 'ultimate-post-kit' ),
504 'type' => Controls_Manager::SLIDER,
505 'size_units' => [ '%' ],
506 'default' => [
507 'unit' => '%',
508 'size' => 100,
509 ],
510 'selectors' => [
511 '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-image img' => 'width: {{SIZE}}{{UNIT}};',
512 ],
513 'condition' => [
514 'style' => '1'
515 ]
516 ]
517 );
518 $this->add_group_control(
519 Group_Control_Border::get_type(),
520 [
521 'name' => 'cat_image_border',
522 'label' => esc_html__( 'Border', 'ultimate-post-kit' ),
523 'selector' => '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-image img',
524 ]
525 );
526
527 $this->add_responsive_control(
528 'cat_image_radius',
529 [
530 'label' => esc_html__( 'Border Radius', 'ultimate-post-kit' ),
531 'type' => Controls_Manager::DIMENSIONS,
532 'size_units' => [ 'px', '%', 'em' ],
533 'selectors' => [
534 '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-image img' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
535 ],
536 ]
537 );
538
539 $this->add_responsive_control(
540 'cat_image_padding',
541 [
542 'label' => esc_html__( 'Padding', 'ultimate-post-kit' ),
543 'type' => Controls_Manager::DIMENSIONS,
544 'size_units' => [ 'px', '%', 'em' ],
545 'selectors' => [
546 '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-image img' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
547 ],
548 ]
549 );
550 $this->add_responsive_control(
551 'cat_image_bottom_spacing',
552 [
553 'label' => esc_html__( 'Spacing', 'ultimate-post-kit' ),
554 'type' => Controls_Manager::SLIDER,
555 'default' => [
556 'unit' => 'px',
557 'size' => 10,
558 ],
559 'selectors' => [
560 '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-image' => 'margin-bottom: {{SIZE}}{{UNIT}};',
561 ],
562 'condition' => [
563 'style' => '1'
564 ],
565 ]
566 );
567
568
569 $this->add_group_control(
570 Group_Control_Box_Shadow::get_type(),
571 [
572 'name' => 'cat_image_box_shadow',
573 'label' => esc_html__( 'Shadow', 'ultimate-post-kit' ),
574 'selector' => '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-image img',
575 ]
576 );
577
578 $this->end_controls_section();
579
580 $this->start_controls_section(
581 'section_style_category_name',
582 [
583 'label' => esc_html__( 'Name', 'ultimate-post-kit' ),
584 'tab' => Controls_Manager::TAB_STYLE,
585 ]
586 );
587
588 $this->add_control(
589 'category_name_color',
590 [
591 'label' => esc_html__( 'Color', 'ultimate-post-kit' ),
592 'type' => Controls_Manager::COLOR,
593 'selectors' => [
594 '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-name' => 'color: {{VALUE}};',
595 ],
596 ]
597 );
598
599 $this->add_control(
600 'category_name_color_hover',
601 [
602 'label' => esc_html__( 'Hover Color', 'ultimate-post-kit' ),
603 'type' => Controls_Manager::COLOR,
604 'selectors' => [
605 '{{WRAPPER}} .upk-post-category .upk-category-item:hover .upk-category-name' => 'color: {{VALUE}};',
606 ],
607 ]
608 );
609
610 $this->add_group_control(
611 Group_Control_Typography::get_type(),
612 [
613 'name' => 'category_name_typography',
614 'label' => esc_html__( 'Typography', 'ultimate-post-kit' ),
615 'selector' => '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-name',
616 ]
617 );
618
619 $this->end_controls_section();
620
621 $this->start_controls_section(
622 'section_style_category_text',
623 [
624 'label' => esc_html__( 'Description', 'ultimate-post-kit' ),
625 'tab' => Controls_Manager::TAB_STYLE,
626 ]
627 );
628
629 $this->add_control(
630 'category_text_color',
631 [
632 'label' => esc_html__( 'Color', 'ultimate-post-kit' ),
633 'type' => Controls_Manager::COLOR,
634 'selectors' => [
635 '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-text' => 'color: {{VALUE}};',
636 ],
637 ]
638 );
639
640 $this->add_control(
641 'category_text_color_hover',
642 [
643 'label' => esc_html__( 'Hover Color', 'ultimate-post-kit' ),
644 'type' => Controls_Manager::COLOR,
645 'selectors' => [
646 '{{WRAPPER}} .upk-post-category .upk-category-item:hover .upk-category-text' => 'color: {{VALUE}};',
647 ],
648 ]
649 );
650
651 $this->add_responsive_control(
652 'category_text_spacing',
653 [
654 'label' => __( 'Spacing', 'ultimate-post-kit' ),
655 'type' => Controls_Manager::SLIDER,
656 'range' => [
657 'px' => [
658 'min' => 0,
659 'max' => 50,
660 ],
661 ],
662 'selectors' => [
663 '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-text' => 'padding-top: {{SIZE}}px;'
664 ],
665 ]
666 );
667
668 $this->add_group_control(
669 Group_Control_Typography::get_type(),
670 [
671 'name' => 'category_text_typography',
672 'label' => esc_html__( 'Typography', 'ultimate-post-kit' ),
673 'selector' => '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-text',
674 ]
675 );
676
677 $this->end_controls_section();
678
679 $this->start_controls_section(
680 'section_style_count',
681 [
682 'label' => esc_html__( 'Count', 'ultimate-post-kit' ),
683 'tab' => Controls_Manager::TAB_STYLE,
684 ]
685 );
686
687 $this->add_control(
688 'count_color',
689 [
690 'label' => esc_html__( 'Color', 'ultimate-post-kit' ),
691 'type' => Controls_Manager::COLOR,
692 'selectors' => [
693 '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-count' => 'color: {{VALUE}};',
694 ],
695 ]
696 );
697
698 $this->add_control(
699 'count_color_hover',
700 [
701 'label' => esc_html__( 'Hover Color', 'ultimate-post-kit' ),
702 'type' => Controls_Manager::COLOR,
703 'selectors' => [
704 '{{WRAPPER}} .upk-post-category .upk-category-item:hover .upk-category-count' => 'color: {{VALUE}};',
705 ],
706 ]
707 );
708
709 $this->add_group_control(
710 Group_Control_Background::get_type(),
711 [
712 'name' => 'count_background',
713 'selector' => '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-count',
714 ]
715 );
716
717 $this->add_group_control(
718 Group_Control_Border::get_type(),
719 [
720 'name' => 'count_border',
721 'selector' => '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-count',
722 ]
723 );
724
725 $this->add_responsive_control(
726 'count_border_radius',
727 [
728 'label' => esc_html__( 'Border Radius', 'ultimate-post-kit' ),
729 'type' => Controls_Manager::DIMENSIONS,
730 'size_units' => [ 'px', '%' ],
731 'selectors' => [
732 '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-count' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
733 ],
734 ]
735 );
736
737 $this->add_responsive_control(
738 'count_padding',
739 [
740 'label' => __( 'Padding', 'ultimate-post-kit' ),
741 'type' => Controls_Manager::DIMENSIONS,
742 'size_units' => [ 'px', 'em', '%' ],
743 'selectors' => [
744 '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-count' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
745 ],
746 ]
747 );
748
749 $this->add_group_control(
750 Group_Control_Box_Shadow::get_type(),
751 [
752 'name' => 'count_box_shadow',
753 'selector' => '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-count',
754 ]
755 );
756
757 $this->add_group_control(
758 Group_Control_Typography::get_type(),
759 [
760 'name' => 'count_typography',
761 'label' => esc_html__( 'Typography', 'ultimate-post-kit' ),
762 'selector' => '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-count',
763 ]
764 );
765
766 $this->add_control(
767 'count_offset_toggle',
768 [
769 'label' => __( 'Offset', 'ultimate-post-kit' ),
770 'type' => Controls_Manager::POPOVER_TOGGLE,
771 'label_off' => __( 'None', 'ultimate-post-kit' ),
772 'label_on' => __( 'Custom', 'ultimate-post-kit' ),
773 'return_value' => 'yes',
774 ]
775 );
776
777 $this->start_popover();
778
779 $this->add_responsive_control(
780 'count_horizontal_offset',
781 [
782 'label' => __( 'Horizontal 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' => 'right: {{SIZE}}px;',
797 ],
798 ]
799 );
800
801 $this->add_responsive_control(
802 'count_vertical_offset',
803 [
804 'label' => __( 'Vertical Offset', 'ultimate-post-kit' ),
805 'type' => Controls_Manager::SLIDER,
806 'range' => [
807 'px' => [
808 'min' => -300,
809 'step' => 2,
810 'max' => 300,
811 ],
812 ],
813 'condition' => [
814 'count_offset_toggle' => 'yes'
815 ],
816 'render_type' => 'ui',
817 'selectors' => [
818 '{{WRAPPER}} .upk-post-category .upk-category-item .upk-category-count' => 'top: {{SIZE}}px;',
819 ],
820 ]
821 );
822
823 $this->end_popover();
824
825 $this->end_controls_section();
826 }
827
828 public function render() {
829 $settings = $this->get_settings_for_display();
830 $image_settings = ultimate_post_kit_option( 'category_image', 'ultimate_post_kit_other_settings', 'off' );
831 $taxonomy = ! empty( $settings['taxonomy'] ) ? $settings['taxonomy'] : 'category';
832 $taxonomy_object = get_taxonomy( $taxonomy );
833 $taxonomy_label = $taxonomy_object ? $taxonomy_object->labels->name : ucwords( str_replace( [ '-', '_' ], ' ', $taxonomy ) );
834 $orderby = $settings['orderby'];
835 $categories = get_categories(
836 [
837 'taxonomy' => $taxonomy,
838 'orderby' => $orderby === 'rand' ? 'name' : $orderby,
839 'order' => $settings["order"],
840 'hide_empty' => 0,
841 // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude -- Elementor widget query built from user-configured controls; expected behaviour.
842 'exclude' => explode( ',', esc_attr( $settings["exclude"] ) ),
843 'parent' => $settings["parent"],
844 ]
845 );
846 if ( $orderby === 'rand' && ! empty( $categories ) ) {
847 shuffle( $categories );
848 }
849
850 $min_post_count = isset( $settings['minimum_post_count'] ) ? (int) $settings['minimum_post_count'] : 0;
851 if ( $min_post_count > 0 ) {
852 $categories = array_values( array_filter( $categories, function ( $cat ) use ( $min_post_count ) {
853 $count = isset( $cat->count ) ? (int) $cat->count : ( isset( $cat->category_count ) ? (int) $cat->category_count : 0 );
854 return $count >= $min_post_count;
855 } ) );
856 }
857
858 $this->add_render_attribute( 'category-container', 'class', 'upk-post-category' );
859 $this->add_render_attribute( 'category-container', 'class', 'upk-category-style-' . $settings['style'] );
860
861 if ( $settings['view_all_button'] == 'yes' ) {
862 $this->add_render_attribute( 'category-container', 'class', 'upk-category-view-all' );
863 }
864
865
866 if ( ! empty( $categories ) ) :
867
868 ?>
869 <div <?php $this->print_render_attribute_string( 'category-container' ); ?>>
870 <?php
871 $multi_bg = isset( $settings['multiple_background'] ) && ! empty( $settings['multiple_background'] ) ? $settings['multiple_background'] : '';
872 $multiple_bg = explode( ',', rtrim( $multi_bg, ',' ) );
873 $total_category = count( $categories );
874
875 // re-creating array for the multiple colors
876 $multiple_bg_create = [];
877 $jCount = count( $multiple_bg );
878 $j = 0;
879 for ( $i = 0; $i < $total_category; $i++ ) {
880 if ( $j == $jCount ) {
881 $j = 0;
882 }
883 $multiple_bg_create[ $i ] = $multiple_bg[ $j ];
884 $j++;
885 }
886
887 foreach ( $categories as $index => $cat ) :
888
889 $this->add_render_attribute( 'category-item', 'class', 'upk-category-item', true );
890
891 $this->add_render_attribute( 'category-item', 'href', get_category_link( $cat->cat_ID ), true );
892
893 $bg_color = strToHex( $cat->cat_name );
894 //===============================
895 // CATEGORY IMAGE
896 $category_image_id = get_term_meta( $cat->cat_ID, 'upk-category-image-id', true );
897
898 if ( ! empty( $category_image_id ) ) {
899 $category_url = wp_get_attachment_image_url( $category_image_id, $settings['cat_image_size_size'] );
900 $category_image = '<div class="upk-category-image"><img src="' . esc_url( $category_url ) . '" alt="' . esc_attr( $cat->cat_name ) . '"></div>';
901 } else {
902 $category_image = '';
903 }
904 //===============================
905
906 if ( ! empty( $settings['multiple_background'] ) ) {
907 $bg_color = $multiple_bg_create[ $index ];
908 if ( ! preg_match( '/#([a-f]|[A-F]|[0-9]){3}(([a-f]|[A-F]|[0-9]){3})?\b/', $multiple_bg_create[ $index ] ) ) {
909 $bg_color = strToHex( $cat->cat_name );
910 }
911 }
912
913 if ( $settings['single_background'] == '' ) {
914 $this->add_render_attribute( 'category-item', 'style', "background-color: $bg_color", true );
915 }
916
917 ?>
918
919 <a <?php $this->print_render_attribute_string( 'category-item' ); ?>>
920 <!-- display image -->
921 <?php if ( $image_settings == 'on' && $settings['show_image'] == 'yes' ) :
922 echo wp_kses_post($category_image);
923 endif; ?>
924 <div class="upk-content">
925 <span class="upk-category-name">
926 <?php echo esc_html( $cat->cat_name ); ?>
927 </span>
928
929 <?php if ( ! empty( $cat->category_description ) and $settings['show_text'] == 'yes' ) : ?>
930 <span class="upk-category-text">
931 <?php echo esc_html( wp_trim_words( $cat->category_description, $settings['text_length'] ) ); ?>
932 </span>
933 <?php endif; ?>
934
935 <?php if ( $settings['show_count'] == 'yes' ) : ?>
936
937 <span class="upk-category-count">
938 <?php echo esc_html( $cat->category_count ); ?>
939 </span>
940 <?php endif; ?>
941 </div>
942
943 <?php if ( $settings['view_all_button'] == 'yes' ) : ?>
944 <div class="upk-category-btn">
945 <span>
946 <?php esc_html_e( 'view all', 'ultimate-post-kit' ); ?>
947 </span>
948 </div>
949 <?php endif; ?>
950
951 </a>
952 <?php
953
954 if ( ! empty( $settings['item_limit']['size'] ) ) {
955 if ( $index == ( $settings['item_limit']['size'] - 1 ) ) {
956 break;
957 }
958 }
959 endforeach;
960 ?>
961 </div>
962 <?php
963 else :
964
965 echo '<div class="upk-alert">' . esc_html( sprintf(
966 /* translators: %s: taxonomy label */
967 __( '%s Categories Not Found!', 'ultimate-post-kit' ),
968 $taxonomy_label
969 ) ) . '</div>';
970
971 endif;
972 }
973 }
974