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