| 1 |
<?php |
| 2 |
function blockspare_epxpress_query_loop_and_wrapper($attributes, $blockclass = '', $design = '', $blockName = '', $layoutClass = false) |
| 3 |
{ |
| 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 |
$grid_query = blockspare_post_query($attributes); |
| 14 |
|
| 15 |
$count = 0; |
| 16 |
if ($grid_query->have_posts()) { |
| 17 |
$alignclass = blockspare_checkalignment($attributes['align']); |
| 18 |
|
| 19 |
/* Build the block classes */ |
| 20 |
$class = "wp-block-blockspare-posts-block-blockspare-posts-block-latest-posts align" . $alignclass . " " . $attributes['blockHoverEffect']; |
| 21 |
|
| 22 |
if (isset($attributes['className'])) { |
| 23 |
$class .= ' ' . $attributes['className']; |
| 24 |
} |
| 25 |
|
| 26 |
if ($attributes['animation']) { |
| 27 |
$class .= ' blockspare-block-animation'; |
| 28 |
} |
| 29 |
|
| 30 |
$list_layout_class = $design; |
| 31 |
$listgridClass = $blockclass . " "; |
| 32 |
|
| 33 |
/* Layout orientation class */ |
| 34 |
$grid_class = 'blockspare-posts-block-latest-post-wrap ' . $listgridClass . ' ' . $list_layout_class; |
| 35 |
$class .= ' ' . $blockuniqueclass; |
| 36 |
$category_class = 'blockspare-posts-block-post-category'; |
| 37 |
|
| 38 |
if ($attributes['categoryLayoutOption'] == 'none') { |
| 39 |
$category_class .= ' has-no-category-style'; |
| 40 |
} ?> |
| 41 |
<!-- <div class="<?php echo esc_attr($class); ?>" blockspare-animation="<?php echo esc_attr($attributes['animation']); ?>"> --> |
| 42 |
<section class="blockspare-posts-block-post-wrap"> |
| 43 |
<div class="<?php echo esc_attr($grid_class); ?>"> |
| 44 |
<?php while ($grid_query->have_posts()) { |
| 45 |
$grid_query->the_post(); |
| 46 |
|
| 47 |
/* Setup the post ID */ |
| 48 |
$post_id = get_the_ID(); |
| 49 |
|
| 50 |
/* Setup the featured image ID */ |
| 51 |
$post_thumb_id = get_post_thumbnail_id($post_id); |
| 52 |
|
| 53 |
$has_img_class = ''; |
| 54 |
|
| 55 |
if (!$post_thumb_id) { |
| 56 |
$has_img_class = "post-has-no-image"; |
| 57 |
} |
| 58 |
|
| 59 |
if ($attributes['enableEqualHeight']) { |
| 60 |
$has_img_class .= ' bs-has-equal-height'; |
| 61 |
} |
| 62 |
$contentOrderClass = ''; |
| 63 |
if ($attributes['contentOrder'] == 'content-order-1') { |
| 64 |
$contentOrderClass .= 'contentorderone'; |
| 65 |
} |
| 66 |
if ($attributes['contentOrder'] == 'content-order-2') { |
| 67 |
$contentOrderClass .= 'contentordertwo'; |
| 68 |
} |
| 69 |
|
| 70 |
/* Setup the post classes */ |
| 71 |
$post_classes = 'blockspare-posts-block-post-single blockspare-hover-item ' . $contentOrderClass; |
| 72 |
|
| 73 |
if ($layoutClass) { |
| 74 |
$post_classes .= ' has-background'; |
| 75 |
} else { |
| 76 |
$post_classes .= ' blockspare-hover-child'; |
| 77 |
} |
| 78 |
|
| 79 |
$className = ''; |
| 80 |
|
| 81 |
if (isset($attributes['full'])) { |
| 82 |
if ($attributes['full'] == 'blockspare-posts-block-full-layout-6') { |
| 83 |
$post_classes .= ' blockspare-hover-child'; |
| 84 |
$className .= 'hover-child'; |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
/* Add sticky class */ |
| 89 |
if (is_sticky($post_id)) { |
| 90 |
$post_classes .= ' sticky'; |
| 91 |
} else { |
| 92 |
$post_classes .= null; |
| 93 |
} |
| 94 |
$post_classes .= ' has-background'; |
| 95 |
?> |
| 96 |
<div id="<?php echo esc_attr($post_id); ?>" class="<?php echo esc_attr($post_classes) . ' ' . $has_img_class; ?>"> |
| 97 |
<?php blockspare_express_post_image($attributes, $post_id, $category_class, $blockName, $className, $count); ?> |
| 98 |
<?php blockspare_express_post_content($attributes, $post_id, $category_class, $blockName, $className, $count); ?> |
| 99 |
</div> |
| 100 |
|
| 101 |
<?php $count++; |
| 102 |
} ?> |
| 103 |
|
| 104 |
</div> |
| 105 |
<?php |
| 106 |
if ($attributes['enablePagination'] == 'true' && $grid_query->max_num_pages > 1) { |
| 107 |
$loadmore_class = ''; |
| 108 |
if ($attributes['loadMoreStyle']) { |
| 109 |
$loadmore_class = $attributes['loadMoreStyle']; |
| 110 |
} |
| 111 |
if ($attributes['loadMoreAlignment']) { |
| 112 |
$loadmore_class .= ' bs_blockspare_loadmore_' . $attributes['loadMoreAlignment']; |
| 113 |
} |
| 114 |
?> |
| 115 |
<div class="bs_blockspare_loadmore blockspare-readmore-wrapper <?php echo esc_attr($loadmore_class); ?>" data-layout="<?php echo $layoutClass; ?>" block-name="express" data-page='2' blockspare-att=<?php echo "'" . wp_kses_post(wp_json_encode($attributes)) . "'"; ?> max-paged="<?php echo $grid_query->max_num_pages; ?>"> |
| 116 |
<a href="#" class="blockspare-readmore"> |
| 117 |
<div class="load-btn "><?php echo ($attributes['loadMoreText']); ?><span class="ajax-loader"></span></div> |
| 118 |
</a> |
| 119 |
</div><?php |
| 120 |
} |
| 121 |
?> |
| 122 |
</section> |
| 123 |
<!-- </div> --> |
| 124 |
<?php |
| 125 |
} |
| 126 |
|
| 127 |
wp_reset_postdata(); |
| 128 |
} |
| 129 |
|
| 130 |
function blockspare_express_post_image($attributes, $post_id, $cat_class, $blockName = '', $className = '', $count = '') |
| 131 |
{ |
| 132 |
|
| 133 |
$spotlightItems = 0; |
| 134 |
if ($attributes['express'] == 'blockspare-posts-block-express-grid-layout-3' || $attributes['express'] == 'blockspare-posts-block-express-grid-layout-6') { |
| 135 |
$spotlightItems = 1; |
| 136 |
} |
| 137 |
/* Setup the featured image ID */ |
| 138 |
$post_thumb_id = get_post_thumbnail_id($post_id); |
| 139 |
|
| 140 |
if (!empty($attributes['imageSize'])) { |
| 141 |
$post_thumb_size = $attributes['imageSize']; |
| 142 |
} |
| 143 |
|
| 144 |
$content_order = false; |
| 145 |
if ($attributes['contentOrder'] == 'content-order-1' || $attributes['contentOrder'] == 'content-order-2') { |
| 146 |
$content_order = true; |
| 147 |
} |
| 148 |
|
| 149 |
if (isset($attributes['enableFeatureImage']) && $attributes['enableFeatureImage'] == true) { |
| 150 |
?> |
| 151 |
<figure class="blockspare-posts-block-post-img hover-child"> |
| 152 |
<a href="<?php echo esc_url(get_permalink($post_id)); ?>" aria-label="<?php echo get_the_title($post_id); ?>"> |
| 153 |
<?php |
| 154 |
if (has_post_thumbnail($post_id)) { |
| 155 |
if ($count <= $spotlightItems) { |
| 156 |
echo wp_kses_post(wp_get_attachment_image($post_thumb_id, $attributes['spotslightImageSize'])); |
| 157 |
} |
| 158 |
if ($count > $spotlightItems) { |
| 159 |
echo wp_kses_post(wp_get_attachment_image($post_thumb_id, $post_thumb_size)); |
| 160 |
} |
| 161 |
} else { ?> |
| 162 |
<div class="bs-no-thumbnail-img"> </div> |
| 163 |
<?php } ?> |
| 164 |
</a> |
| 165 |
<?php if ($attributes['displaySpotlightPostCategory'] == 'true' && $content_order == true && $count <= $spotlightItems) { ?> |
| 166 |
<!-- Spotlight Category --> |
| 167 |
<div class="<?php echo esc_attr($cat_class); ?>"> |
| 168 |
<?php blockspare_get_cat_tax_tags($attributes['taxType'], $post_id, $attributes['postType']); ?> |
| 169 |
</div> |
| 170 |
<!-- Spotlight Category --> |
| 171 |
<?php } ?> |
| 172 |
<?php if ($attributes['displayPostCategory'] == 'true' && $content_order == true && $count > $spotlightItems) { ?> |
| 173 |
<!-- Category --> |
| 174 |
<div class="<?php echo esc_attr($cat_class); ?>"> |
| 175 |
<?php blockspare_get_cat_tax_tags($attributes['taxType'], $post_id, $attributes['postType']); ?> |
| 176 |
</div> |
| 177 |
<!-- Category --> |
| 178 |
<?php } ?> |
| 179 |
</figure> |
| 180 |
<?php |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
function blockspare_express_post_content($attributes, $post_id, $cat_class, $blockName = '', $className = '', $count = '') |
| 185 |
{ |
| 186 |
$spotlightItems = 0; |
| 187 |
if ($attributes['express'] == 'blockspare-posts-block-express-grid-layout-3' || $attributes['express'] == 'blockspare-posts-block-express-grid-layout-6') { |
| 188 |
$spotlightItems = 1; |
| 189 |
} |
| 190 |
$content_order = false; |
| 191 |
if ($attributes['contentOrder'] == 'content-order-1' || $attributes['contentOrder'] == 'content-order-2') { |
| 192 |
$content_order = true; |
| 193 |
} |
| 194 |
if ($blockName == 'full') { |
| 195 |
$content_order = false; |
| 196 |
} |
| 197 |
?> |
| 198 |
<div class="blockspare-posts-block-post-content <?php echo esc_attr($className); ?> <?php echo esc_attr($attributes['contentOrder']); ?> <?php echo esc_attr($attributes['titleOnHover']) ?>"> |
| 199 |
<div class="blockspare-posts-block-bg-overlay"></div> |
| 200 |
<!-- blockspare-posts-block-post-grid-header --> |
| 201 |
<header class="blockspare-posts-block-post-grid-header"> |
| 202 |
<!--display category when feature image is disable --> |
| 203 |
<?php if ($attributes['displayPostCategory'] == 'true' && $attributes['enableFeatureImage'] != 'true') { ?> |
| 204 |
<!-- Category --> |
| 205 |
<div class="<?php echo esc_attr($cat_class); ?>"> |
| 206 |
<?php blockspare_get_cat_tax_tags($attributes['taxType'], $post_id, $attributes['postType']); ?> |
| 207 |
</div> |
| 208 |
<!-- Category --> |
| 209 |
<?php } ?> |
| 210 |
<!--display category when feature image is enable--> |
| 211 |
<?php if ($attributes['displayPostCategory'] == 'true' && $attributes['enableFeatureImage'] == 'true' && $content_order == false) { ?> |
| 212 |
<!-- Category --> |
| 213 |
<div class="<?php echo esc_attr($cat_class); ?>"> |
| 214 |
<?php blockspare_get_cat_tax_tags($attributes['taxType'], $post_id, $attributes['postType']); ?> |
| 215 |
</div> |
| 216 |
<!-- Category --> |
| 217 |
<?php } ?> |
| 218 |
<!-- blockspare-posts-block-post-grid-title --> |
| 219 |
|
| 220 |
<h2 class="blockspare-posts-block-post-grid-title"> |
| 221 |
<a href="<?php echo esc_url(get_permalink($post_id)); ?>" class="blockspare-posts-block-title-link" |
| 222 |
aria-label="<?php echo get_the_title(); ?>"> |
| 223 |
<span><?php echo get_the_title(); ?></span> |
| 224 |
</a> |
| 225 |
</h2> |
| 226 |
|
| 227 |
<!-- blockspare-posts-block-post-grid-title --> |
| 228 |
|
| 229 |
<!-- blockspare-posts-block-post-grid-byline --> |
| 230 |
<div class="blockspare-posts-block-post-grid-byline"> |
| 231 |
<!-- blockspare-posts-block-post-grid-author --> |
| 232 |
<?php if (isset($attributes['displaySpotlightPostAuthor']) && $attributes['displaySpotlightPostAuthor'] == 'true' && $count <= $spotlightItems) { ?> |
| 233 |
<div class="blockspare-posts-block-post-grid-author"> |
| 234 |
|
| 235 |
<?php |
| 236 |
$author_id = get_post_field('post_author', $post_id); |
| 237 |
$blockspare_get_multiauthor = new BlocksapreMultiAuthorForFrontend(); |
| 238 |
$blockspare_get_multiauthor->blockspare_front_by_author($post_id, $attributes['authorIcon'], $author_id); |
| 239 |
?> |
| 240 |
</div> |
| 241 |
<?php } ?> |
| 242 |
<!-- spotlight blockspare-posts-block-post-grid-author --> |
| 243 |
<!-- blockspare-posts-block-post-grid-author --> |
| 244 |
<?php if (isset($attributes['displayPostAuthor']) && $attributes['displayPostAuthor'] == 'true' && $count > $spotlightItems) { ?> |
| 245 |
<div class="blockspare-posts-block-post-grid-author"> |
| 246 |
|
| 247 |
<?php |
| 248 |
$author_id = get_post_field('post_author', $post_id); |
| 249 |
$blockspare_get_multiauthor = new BlocksapreMultiAuthorForFrontend(); |
| 250 |
$blockspare_get_multiauthor->blockspare_front_by_author($post_id, $attributes['authorIcon'], $author_id); |
| 251 |
?> |
| 252 |
</div> |
| 253 |
<?php } ?> |
| 254 |
<!-- blockspare-posts-block-post-grid-author --> |
| 255 |
|
| 256 |
<!-- Spotlight blockspare-posts-block-post-grid-date --> |
| 257 |
<?php if (isset($attributes['displaySpotlightPostDate']) && $attributes['displaySpotlightPostDate'] == 'true' && $count <= $spotlightItems) { ?> |
| 258 |
<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> |
| 259 |
<?php } ?> |
| 260 |
<!-- Spotlight blockspare-posts-block-post-grid-date --> |
| 261 |
<!-- blockspare-posts-block-post-grid-date --> |
| 262 |
<?php if (isset($attributes['displayPostDate']) && $attributes['displayPostDate'] == 'true' && $count > $spotlightItems) { ?> |
| 263 |
<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> |
| 264 |
<?php } ?> |
| 265 |
<!-- blockspare-posts-block-post-grid-date --> |
| 266 |
|
| 267 |
<!-- Spotlight comment_count --> |
| 268 |
<?php if ($attributes['enableSpotlightComment'] == 'true' && $count <= $spotlightItems) { ?> |
| 269 |
<span class="comment_count" aria-label="<?php echo esc_attr(get_comments_number($post_id) . ' comments'); ?>"> |
| 270 |
<i class='<?php echo esc_attr($attributes['commentIcon']); ?>' aria-hidden="true"></i><?php echo esc_html(get_comments_number($post_id)); ?></span> |
| 271 |
<?php } ?> |
| 272 |
<!-- Spotlight --> |
| 273 |
<?php if ($attributes['enableComment'] == 'true' && $count > $spotlightItems) { ?> |
| 274 |
<span class="comment_count" aria-label="<?php echo esc_attr(get_comments_number($post_id) . ' comments'); ?>"> |
| 275 |
<i class='<?php echo esc_attr($attributes['commentIcon']); ?>'></i> |
| 276 |
<?php echo esc_html(get_comments_number($post_id)); ?> |
| 277 |
</span> |
| 278 |
<?php } ?> |
| 279 |
<!-- comment_count --> |
| 280 |
</div> |
| 281 |
<!-- blockspare-posts-block-post-grid-byline --> |
| 282 |
</header> |
| 283 |
<!-- blockspare-posts-block-post-grid-header --> |
| 284 |
|
| 285 |
|
| 286 |
<?php |
| 287 |
|
| 288 |
if ($attributes['displaySpotlightPostExcerpt'] == 'true' && $count <= $spotlightItems) { |
| 289 |
$excerpts = blockspare_excerpt($post_id, $attributes['excerptSpotlightLength']); |
| 290 |
$new_excerpt = apply_filters('the_excerpt', $excerpts); ?> |
| 291 |
<!-- Spotlight blockspare-posts-block-post-grid-excerpt --> |
| 292 |
<?php if ($attributes['displaySpotlightPostExcerpt'] && $new_excerpt != null) { ?> |
| 293 |
<div class="blockspare-posts-block-post-grid-excerpt"> |
| 294 |
<!-- blockspare-posts-block-post-grid-excerpt-content --> |
| 295 |
<?php if (isset($attributes['displaySpotlightPostExcerpt']) && $attributes['displaySpotlightPostExcerpt'] == 'true') { ?> |
| 296 |
<div class="blockspare-posts-block-post-grid-excerpt-content"> |
| 297 |
<?php echo wp_kses_post($excerpts); ?> |
| 298 |
</div> |
| 299 |
<?php } ?> |
| 300 |
<!-- blockspare-posts-block-post-grid-excerpt-content --> |
| 301 |
<!-- blockspare-posts-block-post-grid-more-link --> |
| 302 |
<?php if (isset($attributes['displaySpotPostLink']) && $attributes['displaySpotPostLink'] == 'true') { ?> |
| 303 |
<p> |
| 304 |
<a class="blockspare-posts-block-post-grid-more-link blockspare-posts-block-text-link" |
| 305 |
href="<?php echo esc_url(get_permalink($post_id)); ?>" aria-label="<?php echo get_the_title($post_id); ?>"> |
| 306 |
<span><?php echo esc_html($attributes['readMoreText']); ?></span> |
| 307 |
</a> |
| 308 |
</p> |
| 309 |
<?php } ?> |
| 310 |
<!-- blockspare-posts-block-post-grid-more-link --> |
| 311 |
</div> |
| 312 |
<?php } |
| 313 |
} ?> |
| 314 |
<!-- Spotlight blockspare-posts-block-post-grid-excerpt --> |
| 315 |
<?php |
| 316 |
if ($attributes['displayPostExcerpt'] == 'true' && $count > $spotlightItems) { |
| 317 |
|
| 318 |
$excerpt = blockspare_excerpt($post_id, $attributes['excerptLength']); |
| 319 |
$new_excerpt = apply_filters('the_excerpt', $excerpt); ?> |
| 320 |
<!-- blockspare-posts-block-post-grid-excerpt --> |
| 321 |
<?php if ($attributes['displayPostExcerpt'] && $new_excerpt != null) { ?> |
| 322 |
<div class="blockspare-posts-block-post-grid-excerpt"> |
| 323 |
<!-- blockspare-posts-block-post-grid-excerpt-content --> |
| 324 |
<?php if (isset($attributes['displayPostExcerpt']) && $attributes['displayPostExcerpt'] == 'true' && $count > $spotlightItems) { ?> |
| 325 |
<div class="blockspare-posts-block-post-grid-excerpt-content"> |
| 326 |
<?php echo wp_kses_post($excerpt); ?> |
| 327 |
</div> |
| 328 |
<?php } ?> |
| 329 |
<!-- blockspare-posts-block-post-grid-excerpt-content --> |
| 330 |
<!-- blockspare-posts-block-post-grid-more-link --> |
| 331 |
<?php if (isset($attributes['displayPostLink']) && $attributes['displayPostLink'] == 'true' && $count > $spotlightItems) { ?> |
| 332 |
<p> |
| 333 |
<a |
| 334 |
class="blockspare-posts-block-post-grid-more-link blockspare-posts-block-text-link" |
| 335 |
href="<?php echo esc_url(get_permalink($post_id)); ?>" |
| 336 |
aria-label="<?php echo sprintf(esc_attr__('Read more about %s', 'blockspare'), esc_html(get_the_title($post_id))); ?>"> |
| 337 |
<span aria-hidden="true"><?php echo esc_html($attributes['readMoreText']); ?></span> |
| 338 |
</a> |
| 339 |
</p> |
| 340 |
<?php } ?> |
| 341 |
<!-- blockspare-posts-block-post-grid-more-link --> |
| 342 |
</div> |
| 343 |
<?php } |
| 344 |
} ?> |
| 345 |
<!-- blockspare-posts-block-post-grid-excerpt --> |
| 346 |
|
| 347 |
</div> |
| 348 |
<?php |
| 349 |
} |
| 350 |
|