| 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 |
|
| 15 |
if (isset($attributes['categories']) && ! empty($attributes['categories']) && is_array($attributes['categories'])) { |
| 16 |
$categories = array(); |
| 17 |
$i = 1; |
| 18 |
foreach ($attributes['categories'] as $key => $value) { |
| 19 |
$categories[] = $value['value']; |
| 20 |
} |
| 21 |
} else { |
| 22 |
$categories = array(); |
| 23 |
} |
| 24 |
|
| 25 |
if (isset($attributes['tags']) && ! empty($attributes['tags']) && is_array($attributes['tags'])) { |
| 26 |
$tags = array(); |
| 27 |
$i = 1; |
| 28 |
foreach ($attributes['tags'] as $key => $value) { |
| 29 |
$tags[] = $value['value']; |
| 30 |
} |
| 31 |
} else { |
| 32 |
$tags = array(); |
| 33 |
} |
| 34 |
|
| 35 |
/* Setup the query */ |
| 36 |
|
| 37 |
$query_args = array( |
| 38 |
'posts_per_page' => $attributes['postsToShow'], |
| 39 |
'post_status' => 'publish', |
| 40 |
'order' => $attributes['order'], |
| 41 |
'orderby' => $attributes['orderBy'], |
| 42 |
'offset' => $attributes['offset'], |
| 43 |
'post_type' => $attributes['postType'], |
| 44 |
'ignore_sticky_posts' => 1, |
| 45 |
); |
| 46 |
|
| 47 |
if ($attributes['taxType'] == 'category') { |
| 48 |
$query_args['category__in'] = $categories; |
| 49 |
} |
| 50 |
if ($attributes['taxType'] == 'post_tag') { |
| 51 |
$query_args['tag__in'] = $tags; |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
if ($attributes['taxType'] != 'category' && $attributes['taxType'] != 'post_tag') { |
| 56 |
|
| 57 |
$tax_type = $attributes['taxType']; |
| 58 |
if ($tax_type) { |
| 59 |
$query_args['tax_query'][] = array( |
| 60 |
'taxonomy' => (isset($tax_type)) ? $tax_type : 'category', |
| 61 |
'field' => 'id', |
| 62 |
'terms' => $categories, |
| 63 |
'operator' => 'IN', |
| 64 |
); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
$grid_query = new WP_Query($query_args); |
| 69 |
|
| 70 |
$next = $attributes['carouselNextIcon']; |
| 71 |
$prevstr = str_replace("-right", "-left", $attributes['carouselNextIcon']); |
| 72 |
|
| 73 |
$centermode = false; |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
$responsivelayoutTab = 1; |
| 79 |
$responsivelayoutMobile = 1; |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
if ($attributes['numberofSlide'] > 3) { |
| 84 |
$responsivelayoutTab = 2; |
| 85 |
$responsivelayoutMobile = 1; |
| 86 |
} else { |
| 87 |
$responsivelayoutTab = $attributes['numberofSlide']; |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
$carousel_args = array( |
| 92 |
|
| 93 |
'dots' => $attributes['showDots'], |
| 94 |
'loop' => true, |
| 95 |
'autoplay' => $attributes['enableAutoPlay'], |
| 96 |
'speed' => $attributes['carouselSpeed'], |
| 97 |
'arrows' => $attributes['showsliderNextPrev'], |
| 98 |
'slidesToShow' => 1, |
| 99 |
'centerMode' => $centermode, |
| 100 |
'responsive' => array( |
| 101 |
array( |
| 102 |
'breakpoint' => 900, |
| 103 |
'settings' => array( |
| 104 |
'slidesToShow' => $responsivelayoutTab, |
| 105 |
'slidesToScroll' => 1, |
| 106 |
'infinite' => true, |
| 107 |
'centerMode' => false, |
| 108 |
), |
| 109 |
), |
| 110 |
array( |
| 111 |
'breakpoint' => 600, |
| 112 |
'settings' => array( |
| 113 |
'slidesToShow' => $responsivelayoutTab, |
| 114 |
'slidesToScroll' => 1, |
| 115 |
'centerMode' => false, |
| 116 |
), |
| 117 |
), |
| 118 |
array( |
| 119 |
'breakpoint' => 480, |
| 120 |
'settings' => array( |
| 121 |
'slidesToShow' => $responsivelayoutMobile, |
| 122 |
'slidesToScroll' => 1, |
| 123 |
'centerMode' => false, |
| 124 |
), |
| 125 |
), |
| 126 |
), |
| 127 |
); |
| 128 |
$carousel_args_encoded = wp_json_encode($carousel_args); |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
/* Start the loop */ |
| 133 |
if ($grid_query->have_posts()) { |
| 134 |
$alignclass = blockspare_checkalignment($attributes['align'], $attributes); |
| 135 |
|
| 136 |
/* Build the block classes */ |
| 137 |
$class = "wp-block-blockspare-posts-block-blockspare-posts-block-latest-posts align" . $alignclass . " " . $attributes['blockHoverEffect'] . " " . $attributes['imageHoverEffect'] . " " . $blockuniqueclass; |
| 138 |
|
| 139 |
if (isset($attributes['className'])) { |
| 140 |
$class .= ' ' . $attributes['className']; |
| 141 |
} |
| 142 |
if ($attributes['enableBoxShadow']) { |
| 143 |
$class .= ' bs-has-shadow'; |
| 144 |
} |
| 145 |
$list_layout_class = $attributes['slider']; |
| 146 |
|
| 147 |
|
| 148 |
$hoverNavClass = ''; |
| 149 |
if ($attributes['enableNavInHover']) { |
| 150 |
$hoverNavClass = 'nav-on-hover'; |
| 151 |
} |
| 152 |
//$list_layout_class = $attributes['design']; |
| 153 |
$listgridClass = 'blockspare-posts-block-is-carousel' . " blockspare-posts-block-carousel-full " . "column-" . $attributes['columns'] . ' ' . $attributes['navigationSize'] . ' ' . $attributes['navigationShape'] . ' ' . $hoverNavClass; |
| 154 |
$animation_class = ''; |
| 155 |
if ($attributes['animation']) { |
| 156 |
$animation_class = 'blockspare-block-animation'; |
| 157 |
} |
| 158 |
|
| 159 |
/* Layout orientation class */ |
| 160 |
$grid_class = 'blockspare-posts-block-latest-post-carousel-wrap ' . ' ' . $listgridClass . ' ' . $list_layout_class . ' has-gutter-space-' . $attributes['gutterSpace'] . ' ' . $animation_class; |
| 161 |
|
| 162 |
$category_class = 'blockspare-posts-block-post-category'; |
| 163 |
|
| 164 |
if ($attributes['categoryLayoutOption'] == 'none') { |
| 165 |
$category_class .= ' has-no-category-style'; |
| 166 |
} |
| 167 |
|
| 168 |
?> |
| 169 |
|
| 170 |
<div class="<?php echo esc_attr($class); ?>"> |
| 171 |
<?php echo latest_posts_style_control_slider($blockuniqueclass, $attributes); ?> |
| 172 |
<section class="blockspare-posts-block-post-wrap"> |
| 173 |
<div class="<?php echo esc_attr($grid_class); ?>" blockspare-animation="<?php echo esc_attr($attributes['animation']); ?>"> |
| 174 |
<div class="latest-post-carousel" data-slick="<?php echo esc_attr($carousel_args_encoded); ?>" |
| 175 |
data-next="<?php echo esc_attr($next); ?>" data-prev="<?php echo esc_attr($prevstr); ?>"> |
| 176 |
<?php while ($grid_query->have_posts()) { |
| 177 |
$grid_query->the_post(); |
| 178 |
|
| 179 |
/* Setup the post ID */ |
| 180 |
$post_id = get_the_ID(); |
| 181 |
|
| 182 |
/* Setup the featured image ID */ |
| 183 |
$post_thumb_id = get_post_thumbnail_id($post_id); |
| 184 |
|
| 185 |
$has_img_class = ''; |
| 186 |
|
| 187 |
if (!$post_thumb_id) { |
| 188 |
$has_img_class = "post-has-no-image"; |
| 189 |
} |
| 190 |
|
| 191 |
$contentOrderClass = ''; |
| 192 |
if ($attributes['contentOrder'] == 'content-order-1') { |
| 193 |
$contentOrderClass .= 'contentorderone'; |
| 194 |
} |
| 195 |
if ($attributes['contentOrder'] == 'content-order-2') { |
| 196 |
$contentOrderClass .= 'contentordertwo'; |
| 197 |
} |
| 198 |
|
| 199 |
|
| 200 |
/* Setup the post classes */ |
| 201 |
$post_classes = 'blockspare-posts-block-post-single blockspare-hover-item ' . $contentOrderClass . " " . $attributes['contentOrder']; |
| 202 |
|
| 203 |
if ($attributes['enableEqualHeight']) { |
| 204 |
$post_classes .= ' bs-has-equal-height'; |
| 205 |
} |
| 206 |
|
| 207 |
if ($attributes['slider'] == 'blockspare-posts-block-full-layout-6') { |
| 208 |
$post_classes .= ' blockspare-hover-child'; |
| 209 |
} |
| 210 |
|
| 211 |
/* Add sticky class */ |
| 212 |
if (is_sticky($post_id)) { |
| 213 |
$post_classes .= ' sticky'; |
| 214 |
} else { |
| 215 |
$post_classes .= null; |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
if ($attributes['enableBackgroundColor']) { |
| 221 |
$post_classes .= ' has-background'; |
| 222 |
} |
| 223 |
|
| 224 |
?> |
| 225 |
|
| 226 |
<div id="<?php echo esc_attr($post_id); ?>" |
| 227 |
class="<?php echo esc_attr($post_classes) . ' ' . $has_img_class; ?>"> |
| 228 |
<?php |
| 229 |
|
| 230 |
if (!empty($attributes['imageSize'])) { |
| 231 |
$post_thumb_size = $attributes['imageSize']; |
| 232 |
} ?> |
| 233 |
|
| 234 |
|
| 235 |
<figure class="blockspare-posts-block-post-img hover-child"> |
| 236 |
<a href="<?php echo esc_url(get_permalink($post_id)); ?>" aria-label="<?php echo esc_attr(get_the_title($post_id)); ?>"> |
| 237 |
<?php |
| 238 |
if (has_post_thumbnail($post_id)) { |
| 239 |
echo wp_kses_post(wp_get_attachment_image($post_thumb_id, $post_thumb_size)); |
| 240 |
} else { ?> |
| 241 |
<div class="bs-no-thumbnail-img"> </div> |
| 242 |
<?php } ?> |
| 243 |
</a> |
| 244 |
<?php |
| 245 |
if ($attributes['displayPostCategory']) { ?> |
| 246 |
<div class="<?php echo esc_attr($category_class); ?>"> |
| 247 |
<?php |
| 248 |
/* if($attributes['postType']=='post'){ |
| 249 |
$categories_list = get_the_category_list(' ', '', $post_id); |
| 250 |
if ( $categories_list ) { |
| 251 |
|
| 252 |
printf( esc_html__( '%1$s', 'blockspare' ), $categories_list ); // WPCS: XSS OK. |
| 253 |
} |
| 254 |
} |
| 255 |
if($attributes['postType']!='post'){ |
| 256 |
$terms = get_the_terms($post_id , $attributes['taxType'] ); |
| 257 |
if($terms){ |
| 258 |
foreach($terms as $trem){?> |
| 259 |
<a herf= ><?php echo $trem->name; ?></a> |
| 260 |
<?php } |
| 261 |
} |
| 262 |
} */ |
| 263 |
blockspare_get_cat_tax_tags($attributes['taxType'], $post_id, $attributes['postType']); |
| 264 |
?> |
| 265 |
</div> |
| 266 |
|
| 267 |
<?php } ?> |
| 268 |
</figure> |
| 269 |
|
| 270 |
<div |
| 271 |
class="blockspare-posts-block-post-content hover-child <?php echo esc_attr($attributes['contentOrder']); ?> <?php echo esc_attr($attributes['titleOnHover']) ?>"> |
| 272 |
<div class="blockspare-posts-block-bg-overlay"></div> |
| 273 |
<header class="blockspare-posts-block-post-grid-header"> |
| 274 |
<?php |
| 275 |
if ($attributes['displayPostCategory']) { ?> |
| 276 |
<div class="<?php echo esc_attr($category_class); ?>"> |
| 277 |
<?php |
| 278 |
/* if($attributes['postType']=='post'){ |
| 279 |
$categories_list = get_the_category_list(' ', '', $post_id); |
| 280 |
if ( $categories_list ) { |
| 281 |
|
| 282 |
printf( esc_html__( '%1$s', 'blockspare' ), $categories_list ); // WPCS: XSS OK. |
| 283 |
} |
| 284 |
} |
| 285 |
if($attributes['postType']!='post'){ |
| 286 |
$terms = get_the_terms($post_id , $attributes['taxType'] ); |
| 287 |
if($terms){ |
| 288 |
foreach($terms as $trem){?> |
| 289 |
<a herf= ><?php echo $trem->name; ?></a> |
| 290 |
<?php } |
| 291 |
} |
| 292 |
} |
| 293 |
*/ |
| 294 |
blockspare_get_cat_tax_tags($attributes['taxType'], $post_id, $attributes['postType']); |
| 295 |
?> |
| 296 |
</div> |
| 297 |
<?php } |
| 298 |
$title = get_the_title($post_id); |
| 299 |
if (!$title) { |
| 300 |
$title = __('Untitled', 'blockspare'); |
| 301 |
} ?> |
| 302 |
<h2 class="blockspare-posts-block-post-grid-title"> |
| 303 |
<a href="<?php echo esc_url(get_permalink($post_id)); ?>" |
| 304 |
class="blockspare-posts-block-title-link" rel="bookmark"> |
| 305 |
<span><?php echo ($title); ?></span></a> |
| 306 |
</h2> |
| 307 |
|
| 308 |
<?php |
| 309 |
if (isset($attributes['postType']) && (isset($attributes['displayPostAuthor']) || isset($attributes['displayPostDate']))) { ?> |
| 310 |
<div class="blockspare-posts-block-post-grid-byline"> |
| 311 |
<?php |
| 312 |
if (isset($attributes['displayPostAuthor']) && $attributes['displayPostAuthor']) { ?> |
| 313 |
<div class="blockspare-posts-block-post-grid-author"> |
| 314 |
<?php |
| 315 |
$author_id = get_post_field('post_author', $post_id); |
| 316 |
$blockspare_get_multiauthor = new BlocksapreMultiAuthorForFrontend(); |
| 317 |
$blockspare_get_multiauthor->blockspare_front_by_author($post_id, $attributes['authorIcon'], $author_id); |
| 318 |
?> |
| 319 |
</div> |
| 320 |
<?php } |
| 321 |
|
| 322 |
if (isset($attributes['displayPostDate']) && $attributes['displayPostDate']) { ?> |
| 323 |
<time datetime="<?php echo esc_attr(get_the_date('c', $post_id)); ?>" class="blockspare-posts-block-post-grid-date" itemprop="datePublished"><i class="<?php echo esc_attr($attributes['dateIcon']); ?>" aria-hidden="true"></i><?php echo esc_html(get_the_date('', $post_id)); ?></time> |
| 324 |
<?php } |
| 325 |
|
| 326 |
if ($attributes['enableComment']) { ?> |
| 327 |
<span class="comment_count"><i class='<?php echo esc_attr($attributes['commentIcon']); ?>' aria-hidden="true"></i><?php echo esc_html(get_comments_number($post_id)); ?></span> |
| 328 |
<?php } ?> |
| 329 |
</div> |
| 330 |
|
| 331 |
<?php } ?> |
| 332 |
|
| 333 |
</header> |
| 334 |
|
| 335 |
<?php |
| 336 |
/* Get the excerpt */ |
| 337 |
|
| 338 |
$excerpt = get_post_field( |
| 339 |
'post_excerpt', |
| 340 |
$post_id, |
| 341 |
'display' |
| 342 |
); |
| 343 |
|
| 344 |
if (empty($excerpt)) { |
| 345 |
$excerpt = preg_replace( |
| 346 |
array( |
| 347 |
'/\<figcaption>.*\<\/figcaption>/', |
| 348 |
'/\[caption.*\[\/caption\]/', |
| 349 |
), |
| 350 |
'', |
| 351 |
get_the_content() |
| 352 |
); |
| 353 |
} |
| 354 |
|
| 355 |
// Trim the excerpt if necessary. |
| 356 |
if (isset($attributes['excerptLength'])) { |
| 357 |
$excerpt = wp_trim_words( |
| 358 |
$excerpt, |
| 359 |
$attributes['excerptLength'] |
| 360 |
); |
| 361 |
} |
| 362 |
|
| 363 |
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- This is a WP core filter. |
| 364 |
$excerpt = apply_filters('the_excerpt', $excerpt); |
| 365 |
if ($attributes['displayPostExcerpt'] && $excerpt != null) { ?> |
| 366 |
<div class="blockspare-posts-block-post-grid-excerpt"> |
| 367 |
<?php if (isset($attributes['displayPostExcerpt']) && $attributes['displayPostExcerpt']) { ?> |
| 368 |
<div class="blockspare-posts-block-post-grid-excerpt-content"><?php echo wp_kses_post($excerpt); ?> |
| 369 |
</div> |
| 370 |
<?php } ?> |
| 371 |
|
| 372 |
|
| 373 |
<?php |
| 374 |
|
| 375 |
if (isset($attributes['displayPostLink']) && $attributes['displayPostLink']) { ?> |
| 376 |
<p> |
| 377 |
<a |
| 378 |
class="blockspare-posts-block-post-grid-more-link blockspare-posts-block-text-link" |
| 379 |
href="<?php echo esc_url(get_permalink($post_id)); ?>" |
| 380 |
aria-label="<?php echo sprintf(esc_attr__('Read more about %s', 'blockspare'), esc_html(get_the_title($post_id))); ?>"> |
| 381 |
<span aria-hidden="true"><?php echo esc_html($attributes['readMoreText']); ?></span> |
| 382 |
</a> |
| 383 |
|
| 384 |
</p> |
| 385 |
|
| 386 |
<?php } ?> |
| 387 |
</div> |
| 388 |
<?php } ?> |
| 389 |
</div> |
| 390 |
|
| 391 |
</div> |
| 392 |
<?php } ?> |
| 393 |
</div> |
| 394 |
</div> |
| 395 |
</section> |
| 396 |
</div> |
| 397 |
<?php } |
| 398 |
|