PluginProbe
UiCore Elements – Free widgets and templates for Elementor / 1.3.18
UiCore Elements – Free widgets and templates for Elementor v1.3.18
1.3.18 1.3.17 1.3.16 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.2.0 1.2.1 1.2.2 1.2.3 All 42 releases
← All changes | includes/widgets/post-grid.php +478 -481 1.0.12 → 1.3.18 View file →
@@ -1,481 +1,478 @@
1 -<?php
2 -namespace UiCoreElements;
3 -
4 -use Elementor\Controls_Manager;
5 -use Elementor\Group_Control_Border;
6 -use Elementor\Group_Control_Box_Shadow;
7 -use Elementor\Group_Control_Typography;
8 -use Elementor\Group_Control_Background;
9 -use UiCoreElements\UiCoreWidget;
10 -
11 -use UiCore\Assets;
12 -use UiCore\Portfolio;
13 -use UiCore\Blog;
14 -use UiCore\Helper;
15 -use UiCoreElements\Controls\Post_Filter;
16 -use UiCoreElements\Controls\Query;
17 -
18 -defined('ABSPATH') || exit();
19 -
20 -/**
21 - * Post Grid
22 - *
23 - */
24 -
25 -class PostGrid extends UiCoreWidget
26 -{
27 - private $_query;
28 -
29 - public function __construct($data = [], $args = null)
30 - {
31 - parent::__construct($data, $args);
32 - }
33 - public function get_name()
34 - {
35 - return 'uicore-post-grid';
36 - }
37 - public function get_categories()
38 - {
39 - return ['uicore'];
40 - }
41 - public function get_title()
42 - {
43 - return __('Post Grid', 'uicore-elements');
44 - }
45 - public function get_icon()
46 - {
47 - return 'eicon-gallery-grid ui-e-widget';
48 - }
49 - public function get_keywords()
50 - {
51 - return ['post', 'grid', 'blog', 'recent', 'news'];
52 - }
53 - public function get_styles()
54 - {
55 - return ['post-grid'];
56 - }
57 - public function get_scripts()
58 - {
59 - return [];
60 - }
61 -
62 - public function on_import($element)
63 - {
64 - if (!get_post_type_object($element['settings']['posts-filter_post_type'])) {
65 - $element['settings']['posts-filter_post_type'] = 'post';
66 - }
67 -
68 - return $element;
69 - }
70 - public function on_export($element)
71 - {
72 - $element = Post_Filter::on_export_remove_setting_from_element($element, 'uicore-posts-filter');
73 - return $element;
74 - }
75 -
76 - public function get_query()
77 - {
78 - return $this->_query;
79 - }
80 -
81 - protected function register_controls()
82 - {
83 -
84 - $default_columns = Helper::get_option('blog_col', 3);
85 -
86 - $this->start_controls_section('section_post_grid_def', [
87 - 'label' => esc_html__('Query', 'uicore-elements'),
88 - ]);
89 -
90 - $this->add_group_control(Post_Filter::get_type(), [
91 - 'name' => 'posts-filter',
92 - 'label' => esc_html__('Posts', 'uicore-elements'),
93 - ]);
94 -
95 - $this->add_control('item_limit', [
96 - 'label' => esc_html__('Item Limit', 'uicore-elements'),
97 - 'type' => Controls_Manager::SLIDER,
98 - 'reder_type' => 'template',
99 - 'range' => [
100 - 'px' => [
101 - 'min' => 1,
102 - 'max' => 30,
103 - ],
104 - ],
105 - 'default' => [
106 - 'size' => 3,
107 - ],
108 - ]);
109 - $this->add_control('col_number', [
110 - 'label' => esc_html__('Columns Number', 'uicore-elements'),
111 - 'type' => Controls_Manager::SLIDER,
112 - 'reder_type' => 'template',
113 - 'range' => [
114 - 'px' => [
115 - 'min' => 1,
116 - 'max' => 4,
117 - ],
118 - ],
119 - 'default' => [
120 - 'size' => $default_columns,
121 - ],
122 - ]);
123 -
124 - $this->end_controls_section();
125 -
126 - $this->start_controls_section('section_post_grid_layout', [
127 - 'label' => esc_html__('Layout', 'uicore-elements'),
128 - ]);
129 - $this->add_control(
130 - 'layout',
131 - [
132 - 'label' => __( 'Item Style', 'uicore-elements' ),
133 - 'type' => Controls_Manager::SELECT,
134 - 'default' => 'default',
135 - 'options' => [
136 - 'default' => __( 'Default', 'uicore-elements' ),
137 - 'classic' => __( 'classic', 'uicore-elements' ),
138 - 'grid' => __( 'Grid', 'uicore-elements' ),
139 - 'horizontal' => __( 'Horizontal', 'uicore-elements' ),
140 - 'masonry' => __( 'Masonry', 'uicore-elements' ),
141 - ],
142 - 'condition' => array(
143 - 'posts-filter_post_type!' => 'portfolio',
144 - ),
145 - ]
146 - );
147 -
148 - $this->add_control(
149 - 'box_style',
150 - [
151 - 'label' => __( 'layout', 'uicore-elements' ),
152 - 'type' => Controls_Manager::SELECT,
153 - 'default' => 'default',
154 - 'options' => [
155 - 'default' => __( 'Default', 'uicore-elements' ),
156 - 'boxed' => __( 'Boxed', 'uicore-elements' ),
157 - 'boxed-creative' => __( 'Boxed Creative', 'uicore-elements' ),
158 - 'cover' => __( 'Cover', 'uicore-elements' ),
159 - ],
160 - 'condition' => array(
161 - 'posts-filter_post_type!' => 'portfolio',
162 - ),
163 - ]
164 - );
165 -
166 - $this->add_control(
167 - 'box_ratio',
168 - [
169 - 'label' => __( 'Image Ratio', 'uicore-elements' ),
170 - 'type' => Controls_Manager::SELECT,
171 - 'default' => 'default',
172 - 'options' => [
173 - 'default' => __( 'Default', 'uicore-elements' ),
174 - 'square' => __( 'Square', 'uicore-elements' ),
175 - 'landscape' => __( 'Landscape', 'uicore-elements' ),
176 - 'portrait' => __( 'Portrait', 'uicore-elements' ),
177 - ],
178 - 'condition' => array(
179 - 'posts-filter_post_type!' => 'portfolio',
180 - ),
181 - ]
182 - );
183 - $this->add_control(
184 - 'extra_author',
185 - [
186 - 'label' => __( 'Author', 'uicore-elements' ),
187 - 'type' => Controls_Manager::SWITCHER,
188 - 'return_value' => 'yes',
189 - 'default' => '',
190 - 'reder_type' => 'template',
191 - 'condition' => array(
192 - 'posts-filter_post_type!' => 'portfolio',
193 - ),
194 - ]
195 - );
196 - $this->add_control(
197 - 'extra_date',
198 - [
199 - 'label' => __( 'Date', 'uicore-elements' ),
200 - 'type' => Controls_Manager::SWITCHER,
201 - 'return_value' => 'yes',
202 - 'default' => '',
203 - 'reder_type' => 'template',
204 - 'condition' => array(
205 - 'posts-filter_post_type!' => 'portfolio',
206 - ),
207 - ]
208 - );
209 - $this->add_control(
210 - 'extra_excerpt',
211 - [
212 - 'label' => __( 'Excerpt', 'uicore-elements' ),
213 - 'type' => Controls_Manager::SWITCHER,
214 - 'return_value' => 'yes',
215 - 'default' => '',
216 - 'reder_type' => 'template',
217 - 'condition' => array(
218 - 'posts-filter_post_type!' => 'portfolio',
219 - ),
220 - ]
221 - );
222 - $this->add_control(
223 - 'extra_category',
224 - [
225 - 'label' => __( 'Category', 'uicore-elements' ),
226 - 'type' => Controls_Manager::SWITCHER,
227 - 'return_value' => 'yes',
228 - 'default' => '',
229 - 'reder_type' => 'template',
230 - 'condition' => array(
231 - 'posts-filter_post_type!' => 'portfolio',
232 - ),
233 - ]
234 - );
235 -
236 - $this->end_controls_section();
237 -
238 -
239 - $this->start_controls_section(
240 - 'section_style_typo',
241 - [
242 - 'label' => __( 'Content Style', 'uicore-elements' ),
243 - 'tab' => Controls_Manager::TAB_STYLE,
244 - ]
245 - );
246 -
247 - $this->add_control(
248 - 'post_heading_title',
249 - [
250 - 'label' => esc_html__( 'Post Title', 'uicore-elements' ),
251 - 'type' => Controls_Manager::HEADING,
252 - 'separator' => 'before',
253 - ]
254 - );
255 -
256 - $this->add_control(
257 - 'post_title_color',
258 - [
259 - 'label' => esc_html__( 'Color', 'uicore-elements' ),
260 - 'type' => Controls_Manager::COLOR,
261 - 'default' => '',
262 - 'selectors' => [
263 - '{{WRAPPER}} .uicore-post-title' => 'color: {{VALUE}};',
264 - ],
265 - ]
266 - );
267 -
268 - $this->add_group_control(
269 - Group_Control_Typography::get_type(),
270 - [
271 - 'name' => 'post_title_typography',
272 - 'selector' => '{{WRAPPER}} .uicore-post-title, {{WRAPPER}} .uicore-post-title',
273 - ]
274 - );
275 -
276 -
277 - $this->add_control(
278 - 'extra_excerpt_heading',
279 - [
280 - 'label' => esc_html__( 'Excerpt', 'uicore-elements' ),
281 - 'type' => Controls_Manager::HEADING,
282 - 'separator' => 'before',
283 - ]
284 - );
285 - $this->add_responsive_control(
286 - 'extra_excerpt_bottom_space',
287 - [
288 - 'label' => esc_html__( 'Spacing', 'uicore-elements' ),
289 - 'type' => Controls_Manager::SLIDER,
290 - 'range' => [
291 - 'px' => [
292 - 'min' => 0,
293 - 'max' => 100,
294 - ],
295 - ],
296 - 'selectors' => [
297 - '{{WRAPPER}} .uicore-post-info-wrapper > p' => 'margin-top: {{SIZE}}{{UNIT}};',
298 - ],
299 - ]
300 - );
301 -
302 - $this->add_control(
303 - 'extra_excerpt_color',
304 - [
305 - 'label' => esc_html__( 'Color', 'uicore-elements' ),
306 - 'type' => Controls_Manager::COLOR,
307 - 'default' => '',
308 - 'selectors' => [
309 - '{{WRAPPER}} .uicore-post-info-wrapper > p' => 'color: {{VALUE}};',
310 - ],
311 - ]
312 - );
313 -
314 - $this->add_group_control(
315 - Group_Control_Typography::get_type(),
316 - [
317 - 'name' => 'extra_excerpt_typography',
318 - 'selector' => '{{WRAPPER}} .uicore-post-info-wrapper > p',
319 - ]
320 - );
321 -
322 -
323 - $this->add_responsive_control(
324 - 'box_padding',
325 - [
326 - 'label' => esc_html__( 'Content Padding', 'uicore-elements' ),
327 - 'type' => Controls_Manager::DIMENSIONS,
328 - 'size_units' => [ 'px', 'em', '%', 'rem' ],
329 - 'separator' => 'before',
330 - 'selectors' => [
331 - '{{WRAPPER}} .uicore-blog-grid .uicore-post .uicore-post-info' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}}!important;',
332 - ],
333 - ]
334 - );
335 -
336 - $this->add_group_control(
337 - Group_Control_Background::get_type(),
338 - [
339 - 'name' => 'box_background',
340 - 'selector' => '{{WRAPPER}} .uicore-blog-grid .uicore-post',
341 - ]
342 - );
343 -
344 - $this->add_group_control(
345 - Group_Control_Border::get_type(),
346 - [
347 - 'name' => 'box_border',
348 - 'selector' => '{{WRAPPER}} .uicore-blog-grid .uicore-post',
349 - 'separator' => 'before',
350 - ]
351 - );
352 -
353 - $this->add_control(
354 - 'box_border_radius',
355 - [
356 - 'label' => esc_html__( 'Border Radius', 'uicore-elements' ),
357 - 'type' => Controls_Manager::SLIDER,
358 - 'range' => [
359 - 'px' => [
360 - 'min' => 0,
361 - 'max' => 100,
362 - ],
363 - ],
364 - 'selectors' => [
365 - '{{WRAPPER}} .uicore-blog-grid .uicore-post' => '--uicore-blog--radius: {{SIZE}}{{UNIT}};',
366 - ],
367 - ]
368 - );
369 -
370 - $this->add_group_control(
371 - Group_Control_Box_Shadow::get_type(),
372 - [
373 - 'name' => 'box_shadow_style',
374 - 'selector' => '{{WRAPPER}} .uicore-blog-grid .uicore-post',
375 - ]
376 - );
377 -
378 -
379 - $this->end_controls_section();
380 - }
381 -
382 - public function query_posts($posts_per_page, $type = null)
383 - {
384 - $query_args = Query::get_query_args('posts-filter', $this->get_settings());
385 -
386 - if($type === 'portfolio') {
387 - $query_args['orderby'] = 'menu_order date';
388 - }
389 -
390 - $query_args['posts_per_page'] = $posts_per_page;
391 -
392 - $this->_query = new \WP_Query($query_args);
393 - }
394 -
395 - protected function render()
396 - {
397 - $settings = $this->get_settings();
398 -
399 - $col = $settings['col_number']['size'];
400 - $type = $settings['posts-filter_post_type'];
401 -
402 - if($type != 'portfolio'){
403 -
404 - $type = str_replace(' ', '-', $settings['box_style']);
405 -
406 - // Adds the global css to edit page
407 - if( $this->is_edit_mode()) {
408 - $content = \file_get_contents( Assets::get_global('uicore-blog.css') );
409 - ?>
410 - <style>
411 - <?php echo esc_html(wp_strip_all_tags($content)); ?>
412 - </style>
413 - <?php
414 - }
415 - }
416 -
417 - $this->query_posts($settings['item_limit']['size'], $type);
418 - $wp_query = $this->get_query();
419 -
420 - if (!$wp_query->found_posts) {
421 - echo 'No Posts Found!';
422 - return;
423 - }
424 -
425 -
426 - if ($type === 'portfolio') {
427 -
428 - if( \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
429 - $content = \file_get_contents( Assets::get_global('uicore-portfolio.css') );
430 - ?>
431 - <style>
432 - <?php echo wp_strip_all_tags($content); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
433 - </style>
434 - <?php
435 - }
436 - if(!class_exists('\UiCore\Portfolio\Frontend')){
437 - require_once UICORE_INCLUDES . '/portfolio/class-template.php';
438 - require_once UICORE_INCLUDES . '/portfolio/class-frontend.php';
439 - }
440 - Portfolio\Frontend::frontend_css(true);
441 - $portfolio = new Portfolio\Template('display');
442 - $portfolio->portfolio_layout($wp_query, null, $col);
443 -
444 - } else {
445 - $layout = $settings['layout'] === 'default' ? null : $settings['layout'];
446 - $style = $settings['box_style'] === 'default' ? null : $settings['box_style'];
447 -
448 - if(isset($settings['box_ratio'])){
449 - $ratio = $settings['box_ratio'] === 'default' ? null : $settings['box_ratio'];
450 - }else{//Fallback for older versions
451 - $ratio = null;
452 - }
453 - if(isset($settings['extra_author'])){
454 - $extra = [
455 - 'author' => $settings['extra_author'] === 'yes' ? true : false,
456 - 'date' => $settings['extra_date'] === 'yes' ? true : false,
457 - 'excerpt' => $settings['extra_excerpt'] === 'yes' ? true : false,
458 - 'category' => $settings['extra_category'] === 'yes' ? true : false
459 - ];
460 - }else{ //Fallback for older versions
461 - $extra = [
462 - 'author' => null,
463 - 'date' => null,
464 - 'excerpt' => null,
465 - 'category' => null
466 - ];
467 - }
468 -
469 -
470 - if(!class_exists('\UiCore\Blog\Frontend')){
471 - require_once UICORE_INCLUDES . '/blog/class-template.php';
472 - require_once UICORE_INCLUDES . '/blog/class-frontend.php';
473 - }
474 - Blog\Frontend::frontend_css(true);
475 - $blog = new Blog\Template('display');
476 - $blog->blog_layout($wp_query, $layout, $col,null,$ratio,$extra, $style);
477 - }
478 -
479 - }
480 -}
481 -\Elementor\Plugin::instance()->widgets_manager->register(new PostGrid());
1 +<?php
2 +
3 +namespace UiCoreElements;
4 +
5 +use Elementor\Controls_Manager;
6 +use Elementor\Group_Control_Border;
7 +use Elementor\Group_Control_Box_Shadow;
8 +use Elementor\Group_Control_Typography;
9 +use Elementor\Group_Control_Background;
10 +use UiCoreElements\UiCoreWidget;
11 +
12 +use UiCore\Assets;
13 +use UiCore\Portfolio;
14 +use UiCore\Blog;
15 +use UiCore\Helper;
16 +use UiCoreElements\Controls\Post_Filter;
17 +use UiCoreElements\Controls\Query;
18 +
19 +defined('ABSPATH') || exit();
20 +
21 +/**
22 + * Post Grid
23 + *
24 + */
25 +
26 +class PostGrid extends UiCoreWidget
27 +{
28 + private $_query;
29 +
30 + public function __construct($data = [], $args = null)
31 + {
32 + parent::__construct($data, $args);
33 + }
34 + public function get_name()
35 + {
36 + return 'uicore-post-grid';
37 + }
38 + public function get_categories()
39 + {
40 + return ['uicore'];
41 + }
42 + public function get_title()
43 + {
44 + return __('Post Grid', 'uicore-elements');
45 + }
46 + public function get_icon()
47 + {
48 + return 'eicon-gallery-grid ui-e-widget';
49 + }
50 + public function get_keywords()
51 + {
52 + return ['post', 'grid', 'blog', 'recent', 'news'];
53 + }
54 + public function get_styles()
55 + {
56 + return [
57 + 'post-grid',
58 + // get framework assets
59 + 'uicore-blog-st' => [
60 + 'external' => true,
61 + ],
62 + 'uicore-portfolio-st' => [
63 + 'external' => true,
64 + 'condition' => [
65 + 'posts-filter_post_type' => 'portfolio',
66 + ]
67 + ]
68 + ];
69 + }
70 + public function get_scripts()
71 + {
72 + return [];
73 + }
74 + public function has_widget_inner_wrapper(): bool
75 + {
76 + // TODO: remove after Optmized Markup experiment is merged to the core
77 + return ! \Elementor\Plugin::$instance->experiments->is_feature_active('e_optimized_markup');
78 + }
79 +
80 + public function on_import($element)
81 + {
82 + if (!get_post_type_object($element['settings']['posts-filter_post_type'])) {
83 + $element['settings']['posts-filter_post_type'] = 'post';
84 + }
85 +
86 + return $element;
87 + }
88 + public function on_export($element)
89 + {
90 + $element = Post_Filter::on_export_remove_setting_from_element($element, 'uicore-posts-filter');
91 + return $element;
92 + }
93 +
94 + public function get_query()
95 + {
96 + return $this->_query;
97 + }
98 +
99 + protected function register_controls()
100 + {
101 +
102 + $default_columns = Helper::get_option('blog_col', 3);
103 +
104 + $this->start_controls_section('section_post_grid_def', [
105 + 'label' => esc_html__('Query', 'uicore-elements'),
106 + ]);
107 +
108 + $this->add_group_control(Post_Filter::get_type(), [
109 + 'name' => 'posts-filter',
110 + 'label' => esc_html__('Posts', 'uicore-elements'),
111 + ]);
112 +
113 + $this->add_control('item_limit', [
114 + 'label' => esc_html__('Item Limit', 'uicore-elements'),
115 + 'type' => Controls_Manager::SLIDER,
116 + 'reder_type' => 'template',
117 + 'range' => [
118 + 'px' => [
119 + 'min' => 1,
120 + 'max' => 30,
121 + ],
122 + ],
123 + 'default' => [
124 + 'size' => 3,
125 + ],
126 + ]);
127 + $this->add_control('col_number', [
128 + 'label' => esc_html__('Columns Number', 'uicore-elements'),
129 + 'type' => Controls_Manager::SLIDER,
130 + 'reder_type' => 'template',
131 + 'range' => [
132 + 'px' => [
133 + 'min' => 1,
134 + 'max' => 4,
135 + ],
136 + ],
137 + 'default' => [
138 + 'size' => $default_columns,
139 + ],
140 + ]);
141 +
142 + $this->end_controls_section();
143 +
144 + $this->start_controls_section('section_post_grid_layout', [
145 + 'label' => esc_html__('Layout', 'uicore-elements'),
146 + ]);
147 + $this->add_control(
148 + 'layout',
149 + [
150 + 'label' => __('Item Style', 'uicore-elements'),
151 + 'type' => Controls_Manager::SELECT,
152 + 'default' => 'default',
153 + 'options' => [
154 + 'default' => __('Default', 'uicore-elements'),
155 + 'classic' => __('classic', 'uicore-elements'),
156 + 'grid' => __('Grid', 'uicore-elements'),
157 + 'horizontal' => __('Horizontal', 'uicore-elements'),
158 + 'masonry' => __('Masonry', 'uicore-elements'),
159 + ],
160 + 'condition' => array(
161 + 'posts-filter_post_type!' => 'portfolio',
162 + ),
163 + ]
164 + );
165 +
166 + $this->add_control(
167 + 'box_style',
168 + [
169 + 'label' => __('layout', 'uicore-elements'),
170 + 'type' => Controls_Manager::SELECT,
171 + 'default' => 'default',
172 + 'options' => [
173 + 'default' => __('Default', 'uicore-elements'),
174 + 'boxed' => __('Boxed', 'uicore-elements'),
175 + 'boxed-creative' => __('Boxed Creative', 'uicore-elements'),
176 + 'cover' => __('Cover', 'uicore-elements'),
177 + ],
178 + 'condition' => array(
179 + 'posts-filter_post_type!' => 'portfolio',
180 + ),
181 + ]
182 + );
183 +
184 + $this->add_control(
185 + 'box_ratio',
186 + [
187 + 'label' => __('Image Ratio', 'uicore-elements'),
188 + 'type' => Controls_Manager::SELECT,
189 + 'default' => 'default',
190 + 'options' => [
191 + 'default' => __('Default', 'uicore-elements'),
192 + 'square' => __('Square', 'uicore-elements'),
193 + 'landscape' => __('Landscape', 'uicore-elements'),
194 + 'portrait' => __('Portrait', 'uicore-elements'),
195 + ],
196 + 'condition' => array(
197 + 'posts-filter_post_type!' => 'portfolio',
198 + ),
199 + ]
200 + );
201 + $this->add_control(
202 + 'extra_author',
203 + [
204 + 'label' => __('Author', 'uicore-elements'),
205 + 'type' => Controls_Manager::SWITCHER,
206 + 'return_value' => 'yes',
207 + 'default' => '',
208 + 'reder_type' => 'template',
209 + 'condition' => array(
210 + 'posts-filter_post_type!' => 'portfolio',
211 + ),
212 + ]
213 + );
214 + $this->add_control(
215 + 'extra_date',
216 + [
217 + 'label' => __('Date', 'uicore-elements'),
218 + 'type' => Controls_Manager::SWITCHER,
219 + 'return_value' => 'yes',
220 + 'default' => '',
221 + 'reder_type' => 'template',
222 + 'condition' => array(
223 + 'posts-filter_post_type!' => 'portfolio',
224 + ),
225 + ]
226 + );
227 + $this->add_control(
228 + 'extra_excerpt',
229 + [
230 + 'label' => __('Excerpt', 'uicore-elements'),
231 + 'type' => Controls_Manager::SWITCHER,
232 + 'return_value' => 'yes',
233 + 'default' => '',
234 + 'reder_type' => 'template',
235 + 'condition' => array(
236 + 'posts-filter_post_type!' => 'portfolio',
237 + ),
238 + ]
239 + );
240 + $this->add_control(
241 + 'extra_category',
242 + [
243 + 'label' => __('Category', 'uicore-elements'),
244 + 'type' => Controls_Manager::SWITCHER,
245 + 'return_value' => 'yes',
246 + 'default' => '',
247 + 'reder_type' => 'template',
248 + 'condition' => array(
249 + 'posts-filter_post_type!' => 'portfolio',
250 + ),
251 + ]
252 + );
253 +
254 + $this->end_controls_section();
255 +
256 +
257 + $this->start_controls_section(
258 + 'section_style_typo',
259 + [
260 + 'label' => __('Content Style', 'uicore-elements'),
261 + 'tab' => Controls_Manager::TAB_STYLE,
262 + ]
263 + );
264 +
265 + $this->add_control(
266 + 'post_heading_title',
267 + [
268 + 'label' => esc_html__('Post Title', 'uicore-elements'),
269 + 'type' => Controls_Manager::HEADING,
270 + 'separator' => 'before',
271 + ]
272 + );
273 +
274 + $this->add_control(
275 + 'post_title_color',
276 + [
277 + 'label' => esc_html__('Color', 'uicore-elements'),
278 + 'type' => Controls_Manager::COLOR,
279 + 'default' => '',
280 + 'selectors' => [
281 + '{{WRAPPER}} .uicore-post-title' => 'color: {{VALUE}};',
282 + ],
283 + ]
284 + );
285 +
286 + $this->add_group_control(
287 + Group_Control_Typography::get_type(),
288 + [
289 + 'name' => 'post_title_typography',
290 + 'selector' => '{{WRAPPER}} .uicore-post-title, {{WRAPPER}} .uicore-post-title',
291 + ]
292 + );
293 +
294 +
295 + $this->add_control(
296 + 'extra_excerpt_heading',
297 + [
298 + 'label' => esc_html__('Excerpt', 'uicore-elements'),
299 + 'type' => Controls_Manager::HEADING,
300 + 'separator' => 'before',
301 + ]
302 + );
303 + $this->add_responsive_control(
304 + 'extra_excerpt_bottom_space',
305 + [
306 + 'label' => esc_html__('Spacing', 'uicore-elements'),
307 + 'type' => Controls_Manager::SLIDER,
308 + 'range' => [
309 + 'px' => [
310 + 'min' => 0,
311 + 'max' => 100,
312 + ],
313 + ],
314 + 'selectors' => [
315 + '{{WRAPPER}} .uicore-post-info-wrapper > p' => 'margin-top: {{SIZE}}{{UNIT}};',
316 + ],
317 + ]
318 + );
319 +
320 + $this->add_control(
321 + 'extra_excerpt_color',
322 + [
323 + 'label' => esc_html__('Color', 'uicore-elements'),
324 + 'type' => Controls_Manager::COLOR,
325 + 'default' => '',
326 + 'selectors' => [
327 + '{{WRAPPER}} .uicore-post-info-wrapper > p' => 'color: {{VALUE}};',
328 + ],
329 + ]
330 + );
331 +
332 + $this->add_group_control(
333 + Group_Control_Typography::get_type(),
334 + [
335 + 'name' => 'extra_excerpt_typography',
336 + 'selector' => '{{WRAPPER}} .uicore-post-info-wrapper > p',
337 + ]
338 + );
339 +
340 +
341 + $this->add_responsive_control(
342 + 'box_padding',
343 + [
344 + 'label' => esc_html__('Content Padding', 'uicore-elements'),
345 + 'type' => Controls_Manager::DIMENSIONS,
346 + 'size_units' => ['px', 'em', '%', 'rem'],
347 + 'separator' => 'before',
348 + 'selectors' => [
349 + '{{WRAPPER}} .uicore-blog-grid .uicore-post .uicore-post-info' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}}!important;',
350 + ],
351 + ]
352 + );
353 +
354 + $this->add_group_control(
355 + Group_Control_Background::get_type(),
356 + [
357 + 'name' => 'box_background',
358 + 'selector' => '{{WRAPPER}} .uicore-blog-grid .uicore-post',
359 + ]
360 + );
361 +
362 + $this->add_group_control(
363 + Group_Control_Border::get_type(),
364 + [
365 + 'name' => 'box_border',
366 + 'selector' => '{{WRAPPER}} .uicore-blog-grid .uicore-post',
367 + 'separator' => 'before',
368 + ]
369 + );
370 +
371 + $this->add_control(
372 + 'box_border_radius',
373 + [
374 + 'label' => esc_html__('Border Radius', 'uicore-elements'),
375 + 'type' => Controls_Manager::SLIDER,
376 + 'range' => [
377 + 'px' => [
378 + 'min' => 0,
379 + 'max' => 100,
380 + ],
381 + ],
382 + 'selectors' => [
383 + '{{WRAPPER}} .uicore-blog-grid .uicore-post' => '--uicore-blog--radius: {{SIZE}}{{UNIT}};',
384 + ],
385 + ]
386 + );
387 +
388 + $this->add_group_control(
389 + Group_Control_Box_Shadow::get_type(),
390 + [
391 + 'name' => 'box_shadow_style',
392 + 'selector' => '{{WRAPPER}} .uicore-blog-grid .uicore-post',
393 + ]
394 + );
395 +
396 +
397 + $this->end_controls_section();
398 + }
399 +
400 + public function query_posts($posts_per_page, $type = null)
401 + {
402 + $query_args = Query::get_query_args('posts-filter', $this->get_settings());
403 +
404 + if ($type === 'portfolio') {
405 + $query_args['orderby'] = 'menu_order date';
406 + }
407 +
408 + $query_args['posts_per_page'] = $posts_per_page;
409 +
410 + $this->_query = new \WP_Query($query_args);
411 + }
412 +
413 + protected function render()
414 + {
415 + $settings = $this->get_settings();
416 +
417 + $col = $settings['col_number']['size'];
418 + $type = $settings['posts-filter_post_type'];
419 +
420 + if ($type != 'portfolio') {
421 + $type = str_replace(' ', '-', $settings['box_style']);
422 + }
423 +
424 + $this->query_posts($settings['item_limit']['size'], $type);
425 + $wp_query = $this->get_query();
426 +
427 + if (!$wp_query->found_posts) {
428 + echo 'No Posts Found!';
429 + return;
430 + }
431 +
432 +
433 + if ($type === 'portfolio') {
434 +
435 + if (!class_exists('\UiCore\Portfolio\Frontend')) {
436 + require_once UICORE_INCLUDES . '/portfolio/class-template.php';
437 + require_once UICORE_INCLUDES . '/portfolio/class-frontend.php';
438 + }
439 + Portfolio\Frontend::frontend_css(true);
440 + $portfolio = new Portfolio\Template('display');
441 + $portfolio->portfolio_layout($wp_query, null, $col);
442 + } else {
443 + $layout = $settings['layout'] === 'default' ? null : $settings['layout'];
444 + $style = $settings['box_style'] === 'default' ? null : $settings['box_style'];
445 +
446 + if (isset($settings['box_ratio'])) {
447 + $ratio = $settings['box_ratio'] === 'default' ? null : $settings['box_ratio'];
448 + } else { //Fallback for older versions
449 + $ratio = null;
450 + }
451 + if (isset($settings['extra_author'])) {
452 + $extra = [
453 + 'author' => $this->is_option('extra_author', 'yes'),
454 + 'date' => $this->is_option('extra_date', 'yes'),
455 + 'excerpt' => $this->is_option('extra_excerpt', 'yes'),
456 + 'category' => $this->is_option('extra_category', 'yes')
457 + ];
458 + } else { //Fallback for older versions
459 + $extra = [
460 + 'author' => null,
461 + 'date' => null,
462 + 'excerpt' => null,
463 + 'category' => null
464 + ];
465 + }
466 +
467 +
468 + if (!class_exists('\UiCore\Blog\Frontend')) {
469 + require_once UICORE_INCLUDES . '/blog/class-template.php';
470 + require_once UICORE_INCLUDES . '/blog/class-frontend.php';
471 + }
472 + Blog\Frontend::frontend_css(true);
473 + $blog = new Blog\Template('display');
474 + $blog->blog_layout($wp_query, $layout, $col, null, $ratio, $extra, $style);
475 + }
476 + }
477 +}
478 +\Elementor\Plugin::instance()->widgets_manager->register(new PostGrid());