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

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