PluginProbe
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites / trunk
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites vtrunk
4.1.0 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 2.1.2 2.5.0 2.5.3 2.6.1 All 38 releases
blockspare / build / block / latest-posts-carousel-grid / render.php

render.php in BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites trunk, at build/block/latest-posts-carousel-grid/render.php

237 lines 7.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 wp_enqueue_style('slick');
3 wp_enqueue_script('slick');
4 $unq_class = mt_rand(100000, 999999);
5 $blockuniqueclass = '';
6
7 if (!empty($attributes['uniqueClass'])) {
8 $blockuniqueclass = $attributes['uniqueClass'];
9 } else {
10 $blockuniqueclass = 'blockspare-posts-block-list-' . $unq_class;
11 }
12
13
14 if (isset($attributes['categories']) && ! empty($attributes['categories']) && is_array($attributes['categories'])) {
15 $categories = array();
16 $i = 1;
17 foreach ($attributes['categories'] as $key => $value) {
18 $categories[] = $value['value'];
19 }
20 } else {
21 $categories = array();
22 }
23
24 if (isset($attributes['tags']) && ! empty($attributes['tags']) && is_array($attributes['tags'])) {
25 $tags = array();
26 $i = 1;
27 foreach ($attributes['tags'] as $key => $value) {
28 $tags[] = $value['value'];
29 }
30 } else {
31 $tags = array();
32 }
33
34 /* Setup the query */
35
36 $query_args = array(
37 'posts_per_page' => $attributes['postsToShow'],
38 'post_status' => 'publish',
39 'order' => $attributes['order'],
40 'orderby' => $attributes['orderBy'],
41 'offset' => $attributes['offset'],
42 'post_type' => $attributes['postType'],
43 'ignore_sticky_posts' => 1,
44 );
45
46 if ($attributes['taxType'] == 'category') {
47 $query_args['category__in'] = $categories;
48 }
49 if ($attributes['taxType'] == 'post_tag') {
50 $query_args['tag__in'] = $tags;
51 }
52
53
54 if ($attributes['taxType'] != 'category' && $attributes['taxType'] != 'post_tag') {
55
56 $tax_type = $attributes['taxType'];
57 if ($tax_type) {
58 $query_args['tax_query'][] = array(
59 'taxonomy' => (isset($tax_type)) ? $tax_type : 'category',
60 'field' => 'id',
61 'terms' => $categories,
62 'operator' => 'IN',
63 );
64 }
65 }
66
67 $grid_query = new WP_Query($query_args);
68
69 $next = $attributes['carouselNextIcon'];
70 $prevstr = str_replace("-right", "-left", $attributes['carouselNextIcon']);
71
72 $centermode = false;
73
74 $responsivelayoutTab = 1;
75 $responsivelayoutMobile = 1;
76
77
78 if ($attributes['numberofSlide'] > 2) {
79 $responsivelayoutTab = 2;
80 $responsivelayoutMobile = 1;
81 } else {
82 $responsivelayoutTab = $attributes['numberofSlide'];
83 }
84
85
86 $carousel_args = array(
87
88 'dots' => $attributes['showDots'],
89 'loop' => true,
90 'autoplay' => $attributes['enableAutoPlay'],
91 'speed' => $attributes['carouselSpeed'],
92 'arrows' => $attributes['showsliderNextPrev'],
93 'slidesToShow' => ($attributes['postListingOption'] === 'latest-posts-block-carousel-grid') ? $attributes['numberofSlide'] : 1,
94 'centerMode' => $centermode,
95 'responsive' => array(
96 array(
97 'breakpoint' => 769,
98 'settings' => array(
99 'slidesToShow' => $responsivelayoutTab,
100 'slidesToScroll' => 1,
101 'infinite' => true,
102 'centerMode' => false,
103 ),
104 ),
105
106 array(
107 'breakpoint' => 481,
108 'settings' => array(
109 'slidesToShow' => $responsivelayoutMobile,
110 'slidesToScroll' => 1,
111 'centerMode' => false,
112 ),
113 ),
114 ),
115 );
116 $carousel_args_encoded = wp_json_encode($carousel_args);
117
118
119
120 /* Start the loop */
121 if ($grid_query->have_posts()) {
122 $alignclass = blockspare_checkalignment($attributes['align'], $attributes);
123 /* Build the block classes */
124 $class = "wp-block-blockspare-posts-block-blockspare-posts-block-latest-posts align" . $alignclass . ' ' . $attributes['blockHoverEffect'] . ' ' . $attributes['imageHoverEffect'] . ' ' . $blockuniqueclass;
125
126 if (isset($attributes['className'])) {
127 $class .= ' ' . $attributes['className'];
128 }
129 if ($attributes['enableBoxShadow']) {
130 $class .= ' bs-has-shadow';
131 }
132
133 $list_layout_class = $attributes['grid'];
134
135
136 $hoverNavClass = '';
137 if ($attributes['enableNavInHover']) {
138 $hoverNavClass = 'nav-on-hover';
139 }
140 //$list_layout_class = $attributes['design'];
141 $listgridClass = 'blockspare-posts-block-is-carousel' . " " . $attributes['navigationSize'] . ' ' . $attributes['navigationShape'] . ' ' . $hoverNavClass . ' blockspare-slides-' . $attributes['numberofSlide'];
142
143 $animation_class = '';
144 if ($attributes['animation']) {
145 $animation_class = 'blockspare-block-animation';
146 }
147
148
149 /* Layout orientation class */
150 $grid_class = 'blockspare-posts-block-latest-post-carousel-wrap blockspare-posts-block-latest-post-wrap' . ' ' . $listgridClass . ' ' . $list_layout_class . ' has-gutter-space-' . $attributes['gutterSpace'] . " " . $attributes['postListingOption'] . ' ' . $animation_class;
151
152 $category_class = 'blockspare-posts-block-post-category';
153
154 if ($attributes['categoryLayoutOption'] == 'none') {
155 $category_class .= ' has-no-category-style';
156 }
157
158
159
160 $enableFeatureImage = true;
161 if (isset($attributes['enableFeatureImage'])) {
162 $enableFeatureImage = $attributes['enableFeatureImage'];
163 }
164 ?>
165
166 <div class="<?php echo esc_attr($class); ?>">
167 <?php echo latest_posts_style_control_carousel($blockuniqueclass, $attributes); ?>
168 <section class="blockspare-posts-block-post-wrap">
169
170 <div class="<?php echo esc_attr($grid_class); ?>" blockspare-animation="<?php echo esc_attr($attributes['animation']); ?>">
171 <div class="latest-post-carousel" data-slick="<?php echo esc_attr($carousel_args_encoded); ?>"
172 data-next="<?php echo esc_attr($next); ?>" data-prev="<?php echo esc_attr($prevstr); ?>">
173 <?php while ($grid_query->have_posts()) {
174 $grid_query->the_post();
175
176 /* Setup the post ID */
177 $post_id = get_the_ID();
178
179 /* Setup the featured image ID */
180 $post_thumb_id = get_post_thumbnail_id($post_id);
181
182 $has_img_class = '';
183
184 if (!$post_thumb_id) {
185 $has_img_class = "post-has-no-image";
186 }
187
188 $contentOrderClass = '';
189 if ($attributes['contentOrder'] == 'content-order-1') {
190 $contentOrderClass .= 'contentorderone';
191 }
192 if ($attributes['contentOrder'] == 'content-order-2') {
193 $contentOrderClass .= 'contentordertwo';
194 }
195
196
197 /* Setup the post classes */
198 $post_classes = 'blockspare-posts-block-post-single blockspare-hover-item ' . $contentOrderClass;
199 if ($attributes['enableEqualHeight']) {
200 $post_classes .= ' bs-has-equal-height';
201 }
202
203 $layoutclass = false;
204
205 if ($attributes['grid'] != 'blockspare-posts-block-grid-layout-3' && $attributes['grid'] != 'blockspare-posts-block-grid-layout-4') {
206 $layoutclass = true;
207 }
208
209 if ($layoutclass) {
210 $post_classes .= ' has-background';
211 } else {
212 $post_classes .= ' blockspare-hover-child';
213 }
214
215
216 /* Add sticky class */
217 if (is_sticky($post_id)) {
218 $post_classes .= ' sticky';
219 } else {
220 $post_classes .= null;
221 }
222 ?>
223 <div>
224 <div id="<?php echo esc_attr($post_id); ?>" class="<?php echo esc_attr($post_classes) . ' ' . $has_img_class; ?>">
225 <?php blockspare_post_image($attributes, $post_id, $category_class, $blockName = '', $count = '', $enableFeatureImage); ?>
226 <?php blockspare_post_content($attributes, $post_id, $category_class); ?>
227 </div>
228 </div>
229
230
231 <?php } ?>
232 </div>
233 </div>
234 </section>
235 </div>
236 <?php }
237