| @@ -1,387 +1,522 @@ | ||
| 1 | -<?php | |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | -exit; // Exit if accessed directly. | |
| 1 | +<?php | |
| 2 | +if (! defined('ABSPATH')) { | |
| 3 | + exit; // Exit if accessed directly. | |
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | |
| 7 | -function blockspare_post_query($attributes){ | |
| 7 | +function blockspare_post_query($attributes) | |
| 8 | +{ | |
| 9 | + $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; | |
| 10 | + if (isset($attributes['categories']) && ! empty($attributes['categories']) && is_array($attributes['categories'])) { | |
| 11 | + $categories = array(); | |
| 12 | + $i = 1; | |
| 13 | + foreach ($attributes['categories'] as $key => $value) { | |
| 14 | + $categories[] = $value['value']; | |
| 15 | + } | |
| 16 | + } else { | |
| 17 | + $categories = array(); | |
| 18 | + } | |
| 8 | 19 | |
| 9 | - $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; | |
| 10 | - | |
| 11 | - if ( isset( $attributes['categories'] ) && ! empty( $attributes['categories'] ) && is_array( $attributes['categories'] ) ) { | |
| 12 | - $categories = array(); | |
| 13 | - $i = 1; | |
| 14 | - foreach ( $attributes['categories'] as $key => $value ) { | |
| 15 | - $categories[] = $value['value']; | |
| 20 | + if (isset($attributes['tags']) && ! empty($attributes['tags']) && is_array($attributes['tags'])) { | |
| 21 | + $tags = array(); | |
| 22 | + $i = 1; | |
| 23 | + foreach ($attributes['tags'] as $key => $value) { | |
| 24 | + $tags[] = $value['value']; | |
| 25 | + } | |
| 26 | + } else { | |
| 27 | + $tags = array(); | |
| 28 | + } | |
| 29 | + | |
| 30 | + /* Setup the query */ | |
| 31 | + $currentID = get_the_ID(); | |
| 32 | + $query_args = array( | |
| 33 | + 'posts_per_page' => $attributes['postsToShow'], | |
| 34 | + 'post_status' => 'publish', | |
| 35 | + 'order' => $attributes['order'], | |
| 36 | + 'orderby' => $attributes['orderBy'], | |
| 37 | + 'offset' => ($attributes['enablePagination'] == 'true') ? '' : $attributes['offset'], | |
| 38 | + 'post_type' => $attributes['postType'], | |
| 39 | + 'ignore_sticky_posts' => 1, | |
| 40 | + 'paged' => $paged, | |
| 41 | + 'post__not_in' => array($currentID) | |
| 42 | + ); | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + if ('post' != $attributes['postType']) { | |
| 48 | + | |
| 49 | + $tax_type = $attributes['taxType']; | |
| 50 | + if ($tax_type) { | |
| 51 | + if (!empty($categories)) { | |
| 52 | + $query_args['tax_query'][] = array( | |
| 53 | + 'taxonomy' => (isset($tax_type)) ? $tax_type : 'category', | |
| 54 | + 'field' => 'id', | |
| 55 | + 'terms' => $categories, | |
| 56 | + 'operator' => 'IN', | |
| 57 | + ); | |
| 58 | + } | |
| 59 | + } | |
| 60 | + } | |
| 61 | + | |
| 62 | + if ('post' == $attributes['postType']) { | |
| 63 | + | |
| 64 | + $tax_type = $attributes['taxType']; | |
| 65 | + if ($tax_type) { | |
| 66 | + if (!empty($categories)) { | |
| 67 | + $query_args['tax_query'][] = array( | |
| 68 | + 'taxonomy' => (isset($tax_type)) ? $tax_type : 'category', | |
| 69 | + 'field' => 'id', | |
| 70 | + 'terms' => $categories, | |
| 71 | + 'operator' => 'IN', | |
| 72 | + ); | |
| 73 | + } else { | |
| 74 | + | |
| 75 | + $taxonomy = $tax_type; // this is the name of the taxonomy | |
| 76 | + $terms = get_terms($taxonomy); | |
| 77 | + if (!empty($terms)) { | |
| 78 | + $query_args['tax_query'][] = array( | |
| 79 | + 'taxonomy' => (isset($tax_type)) ? $tax_type : 'category', | |
| 80 | + 'field' => 'slug', | |
| 81 | + 'terms' => wp_list_pluck($terms, 'slug') | |
| 82 | + | |
| 83 | + ); | |
| 16 | 84 | } |
| 17 | - } else { | |
| 18 | - $categories = array(); | |
| 85 | + } | |
| 19 | 86 | } |
| 87 | + } | |
| 20 | 88 | |
| 21 | - if ( isset( $attributes['tags'] ) && ! empty( $attributes['tags'] ) && is_array( $attributes['tags'] ) ) { | |
| 22 | - $tags = array(); | |
| 23 | - $i = 1; | |
| 24 | - foreach ( $attributes['tags'] as $key => $value ) { | |
| 25 | - $tags[] = $value['value']; | |
| 26 | - } | |
| 27 | - } else { | |
| 28 | - $tags = array(); | |
| 89 | + if ($attributes['taxType'] == 'category') { | |
| 90 | + $query_args['category__in'] = $categories; | |
| 91 | + } | |
| 92 | + if ($attributes['taxType'] == 'post_tag') { | |
| 93 | + $query_args['tag__in'] = $tags; | |
| 94 | + } | |
| 95 | + /* Setup the query */ | |
| 96 | + $grid_query = new WP_Query($query_args); | |
| 97 | + return $grid_query; | |
| 98 | +} | |
| 99 | + | |
| 100 | +function blockspare_query_loop_and_wrapper($attributes, $blockclass = '', $design = '', $blockName = '', $paged = '', $layoutClass = false) | |
| 101 | +{ | |
| 102 | + | |
| 103 | + if ($attributes['enablePagination']) { | |
| 104 | + wp_enqueue_script('blockspare-pagination-js'); | |
| 105 | + } | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + $unq_class = mt_rand(100000, 999999); | |
| 110 | + $blockuniqueclass = ''; | |
| 111 | + | |
| 112 | + if (!empty($attributes['uniqueClass'])) { | |
| 113 | + $blockuniqueclass = $attributes['uniqueClass']; | |
| 114 | + } else { | |
| 115 | + $blockuniqueclass = 'blockspare-posts-block-list-' . $unq_class; | |
| 116 | + } | |
| 117 | + | |
| 118 | + $grid_query = blockspare_post_query($attributes); | |
| 119 | + | |
| 120 | + | |
| 121 | + if ($grid_query->have_posts()) { | |
| 122 | + | |
| 123 | + $alignclass = blockspare_checkalignment($attributes['align']); | |
| 124 | + | |
| 125 | + | |
| 126 | + /* Build the block classes */ | |
| 127 | + $class = "wp-block-blockspare-posts-block-blockspare-posts-block-latest-posts align" . $alignclass . " " . $attributes['blockHoverEffect']; | |
| 128 | + | |
| 129 | + if (isset($attributes['className'])) { | |
| 130 | + $class .= ' ' . $attributes['className']; | |
| 29 | 131 | } |
| 30 | - | |
| 31 | - /* Setup the query */ | |
| 32 | 132 | |
| 33 | - $query_args = array( | |
| 34 | - 'posts_per_page' => $attributes['postsToShow'], | |
| 35 | - 'post_status' => 'publish', | |
| 36 | - 'order' => $attributes['order'], | |
| 37 | - 'orderby' => $attributes['orderBy'], | |
| 38 | - 'offset' => ($attributes['enablePagination']=='true')?'':$attributes['offset'], | |
| 39 | - 'post_type' => $attributes['postType'], | |
| 40 | - 'ignore_sticky_posts' => 1, | |
| 41 | - 'paged'=>$paged | |
| 42 | - ); | |
| 43 | 133 | |
| 44 | - if($attributes['taxType'] =='category'){ | |
| 45 | - $query_args['category__in'] =$categories; | |
| 46 | - | |
| 134 | + if ($attributes['animation']) { | |
| 135 | + $class .= ' blockspare-block-animation'; | |
| 47 | 136 | } |
| 48 | - if($attributes['taxType'] =='post_tag'){ | |
| 49 | - $query_args['tag__in'] =$tags; | |
| 50 | - | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + $list_layout_class = $design; | |
| 141 | + $listgridClass = $blockclass . " "; | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + // if($blockName=='' ){ | |
| 146 | + // $listgridClass .= "column-" . $attributes['columns']; | |
| 147 | + // } | |
| 148 | + | |
| 149 | + | |
| 150 | + /* Layout orientation class */ | |
| 151 | + $grid_class = 'blockspare-posts-block-latest-post-wrap ' . $listgridClass . ' ' . $list_layout_class; | |
| 152 | + // if ($blockName != 'post-grid-masonry'){ | |
| 153 | + // $grid_class .= ' ' . $blockuniqueclass; | |
| 154 | + // }else{ | |
| 155 | + $class .= ' ' . $blockuniqueclass; | |
| 156 | + // } | |
| 157 | + $category_class = 'blockspare-posts-block-post-category'; | |
| 158 | + | |
| 159 | + if ($attributes['categoryLayoutOption'] == 'none') { | |
| 160 | + $category_class .= ' has-no-category-style'; | |
| 51 | 161 | } |
| 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 | - } | |
| 162 | + | |
| 163 | + $enableFeatureImage = true; | |
| 164 | + if (isset($attributes['enableFeatureImage'])) { | |
| 165 | + $enableFeatureImage = $attributes['enableFeatureImage']; | |
| 65 | 166 | } |
| 66 | - /* Setup the query */ | |
| 67 | - $grid_query = new WP_Query($query_args); | |
| 68 | - return $grid_query; | |
| 69 | -} | |
| 70 | 167 | |
| 71 | -function blockspare_query_loop_and_wrapper($attributes,$blockclass ='',$design='',$blockName=''){ | |
| 72 | - $unq_class = mt_rand(100000,999999); | |
| 73 | - $blockuniqueclass = ''; | |
| 74 | - | |
| 75 | - if(!empty($attributes['uniqueClass'])){ | |
| 76 | - $blockuniqueclass = $attributes['uniqueClass']; | |
| 77 | - }else{ | |
| 78 | - $blockuniqueclass = 'blockspare-posts-block-list-'.$unq_class; | |
| 79 | - } | |
| 80 | - | |
| 81 | - $grid_query = blockspare_post_query($attributes); | |
| 82 | - if ($grid_query->have_posts()) { | |
| 83 | - $alignclass = blockspare_checkalignment($attributes['align']); | |
| 168 | +?> | |
| 84 | 169 | |
| 85 | - | |
| 86 | - /* Build the block classes */ | |
| 87 | - $class = "wp-block-blockspare-posts-block-blockspare-posts-block-latest-posts blockspare-posts-block-post-wrap align".$alignclass." ".$attributes['blockHoverEffect'] ; | |
| 88 | - | |
| 89 | - if (isset($attributes['className'])) { | |
| 90 | - $class .= ' ' . $attributes['className']; | |
| 91 | - } | |
| 170 | + <section class="blockspare-posts-block-post-wrap"> | |
| 171 | + <div class="<?php echo esc_attr($grid_class); ?>"> | |
| 172 | + <?php | |
| 173 | + $count = 0; | |
| 174 | + while ($grid_query->have_posts()) { | |
| 175 | + $grid_query->the_post(); | |
| 92 | 176 | |
| 93 | - $animation_class = ''; | |
| 94 | - if( $attributes['animation']){ | |
| 95 | - $animation_class='blockspare-block-animation'; | |
| 96 | - } | |
| 177 | + /* Setup the post ID */ | |
| 178 | + $post_id = get_the_ID(); | |
| 97 | 179 | |
| 98 | - | |
| 99 | 180 | |
| 100 | - $list_layout_class = $design; | |
| 101 | - $listgridClass = $blockclass . " " ; | |
| 102 | - | |
| 103 | - if($blockName=='' ){ | |
| 104 | - $listgridClass .= "column-" . $attributes['columns']; | |
| 105 | - } | |
| 106 | - | |
| 107 | - | |
| 108 | - /* Layout orientation class */ | |
| 109 | - $grid_class = $blockuniqueclass . ' blockspare-posts-block-latest-post-wrap ' . $listgridClass . ' ' . $list_layout_class.' '.$animation_class ; | |
| 110 | - | |
| 111 | - $category_class = 'blockspare-posts-block-post-category'; | |
| 112 | - | |
| 113 | - if($attributes['categoryLayoutOption'] =='none'){ | |
| 114 | - $category_class .= ' has-no-category-style'; | |
| 115 | - }?> | |
| 116 | - <section class="<?php echo esc_attr($class);?>"> | |
| 117 | - <div class="<?php echo esc_attr($grid_class);?>" blockspare-animation=<?php echo esc_attr( $attributes['animation'] )?>> | |
| 118 | - <?php while ($grid_query->have_posts()) { | |
| 119 | - $grid_query->the_post(); | |
| 120 | - | |
| 121 | - /* Setup the post ID */ | |
| 122 | - $post_id = get_the_ID(); | |
| 123 | - | |
| 124 | - /* Setup the featured image ID */ | |
| 125 | - $post_thumb_id = get_post_thumbnail_id($post_id); | |
| 126 | - | |
| 127 | - $has_img_class = ''; | |
| 128 | - | |
| 129 | - if (!$post_thumb_id) { | |
| 130 | - $has_img_class = "post-has-no-image"; | |
| 131 | - } | |
| 181 | + /* Setup the featured image ID */ | |
| 182 | + $post_thumb_id = get_post_thumbnail_id($post_id); | |
| 132 | 183 | |
| 133 | - | |
| 134 | - | |
| 135 | - | |
| 136 | - if(isset($attributes['full'])){ | |
| 137 | - if($attributes['full']== 'blockspare-posts-block-full-layout-4' ){ | |
| 138 | - $attributes['enableEqualHeight'] = false; | |
| 139 | - } | |
| 184 | + $has_img_class = ''; | |
| 140 | 185 | |
| 141 | - } | |
| 186 | + if (!$post_thumb_id) { | |
| 187 | + $has_img_class = "post-has-no-image "; | |
| 188 | + } | |
| 142 | 189 | |
| 143 | - | |
| 144 | - if($attributes['enableEqualHeight']){ | |
| 145 | - $has_img_class .=' bs-has-equal-height'; | |
| 146 | - } | |
| 147 | - $contentOrderClass =''; | |
| 148 | - if($attributes['contentOrder']=='content-order-1'){ | |
| 149 | - $contentOrderClass .= 'contentorderone'; | |
| 150 | - } | |
| 151 | - if( $attributes['contentOrder']=='content-order-2'){ | |
| 152 | - $contentOrderClass .= 'contentordertwo'; | |
| 153 | - } | |
| 154 | - | |
| 155 | - /* Setup the post classes */ | |
| 156 | - $post_classes = 'blockspare-posts-block-post-single '. $contentOrderClass; | |
| 157 | - | |
| 158 | - /* Add sticky class */ | |
| 159 | - if (is_sticky($post_id)) { | |
| 160 | - $post_classes .= ' sticky'; | |
| 161 | - } else { | |
| 162 | - $post_classes .= null; | |
| 163 | - } | |
| 164 | - $post_classes .= ' has-background'; | |
| 165 | - ?> | |
| 166 | - <div id="<?php echo esc_attr($post_id);?>" class="<?php echo esc_attr($post_classes).' '.$has_img_class; ?>"> | |
| 167 | - <?php blockspare_post_image($attributes,$post_id,$category_class,$blockName);?> | |
| 168 | - <?php blockspare_post_content($attributes,$post_id,$category_class,$blockName);?> | |
| 169 | - </div> | |
| 170 | 190 | |
| 171 | - <?php }?> | |
| 172 | 191 | |
| 192 | + | |
| 193 | + if (isset($attributes['full'])) { | |
| 194 | + if ($attributes['full'] == 'blockspare-posts-block-full-layout-4') { | |
| 195 | + $attributes['enableEqualHeight'] = false; | |
| 196 | + } | |
| 197 | + } | |
| 198 | + | |
| 199 | + | |
| 200 | + if ($attributes['enableEqualHeight']) { | |
| 201 | + $has_img_class .= 'bs-has-equal-height'; | |
| 202 | + } | |
| 203 | + $contentOrderClass = ''; | |
| 204 | + if ($attributes['contentOrder'] == 'content-order-1') { | |
| 205 | + $contentOrderClass .= 'contentorderone'; | |
| 206 | + } | |
| 207 | + if ($attributes['contentOrder'] == 'content-order-2') { | |
| 208 | + $contentOrderClass .= 'contentordertwo'; | |
| 209 | + } | |
| 210 | + | |
| 211 | + /* Setup the post classes */ | |
| 212 | + $post_classes = 'blockspare-posts-block-post-single blockspare-hover-item ' . $contentOrderClass; | |
| 213 | + | |
| 214 | + if ($layoutClass) { | |
| 215 | + $post_classes .= ' has-background'; | |
| 216 | + } else { | |
| 217 | + $post_classes .= ' blockspare-hover-child'; | |
| 218 | + } | |
| 219 | + | |
| 220 | + $className = ''; | |
| 221 | + if (isset($attributes['full'])) { | |
| 222 | + if ($attributes['full'] == 'blockspare-posts-block-full-layout-6') { | |
| 223 | + $post_classes .= ' blockspare-hover-child'; | |
| 224 | + $className .= 'hover-child'; | |
| 225 | + } | |
| 226 | + } | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + /* Add sticky class */ | |
| 232 | + if (is_sticky($post_id)) { | |
| 233 | + $post_classes .= ' sticky'; | |
| 234 | + } else { | |
| 235 | + $post_classes .= null; | |
| 236 | + } | |
| 237 | + if ($blockName == 'post-grid-masonry') { | |
| 238 | + ?> | |
| 239 | + <div class="blockspare-posts-masonry-item-wrapper"> | |
| 240 | + <?php } ?> | |
| 241 | + <div id="<?php echo esc_attr($post_id); ?>" class="<?php echo esc_attr($post_classes) . ' ' . $has_img_class; ?>"> | |
| 242 | + <?php blockspare_post_image($attributes, $post_id, $category_class, $blockName, $count, $enableFeatureImage); ?> | |
| 243 | + <?php blockspare_post_content($attributes, $post_id, $category_class, $blockName, $className); ?> | |
| 173 | 244 | </div> |
| 174 | - <?php | |
| 175 | - if($attributes['enablePagination']=='true' && $grid_query->max_num_pages >1){ ?> | |
| 176 | - <div class="bs_blockspare_loadmore blockspare-readmore-wrapper" block-name="tile" data-page='2' blockspare-att=<?php echo "'" . wp_kses_post(wp_json_encode($attributes))."'";?> max-paged="<?php echo $grid_query->max_num_pages;?>"> | |
| 177 | - <a href="#" class="blockspare-readmore"> | |
| 178 | - <div class="ajax-loader"></div> | |
| 179 | - <span class="load-btn"><?php echo($attributes['loadMoreText']); ?></span> | |
| 180 | - </a> | |
| 181 | - </div><?php | |
| 182 | - } | |
| 245 | + <?php | |
| 246 | + if ($blockName == 'post-grid-masonry') { | |
| 183 | 247 | ?> |
| 184 | - </section> | |
| 185 | - <?php } | |
| 248 | + </div> | |
| 249 | + <?php } ?> | |
| 250 | + <?php $count++; | |
| 251 | + } ?> | |
| 186 | 252 | |
| 187 | -wp_reset_postdata(); | |
| 188 | 253 | |
| 189 | -} | |
| 190 | 254 | |
| 255 | + </div> | |
| 191 | 256 | |
| 192 | -function blockspare_post_image($attributes,$post_id,$cat_class ,$blockName=''){ | |
| 257 | + <?php | |
| 258 | + if ($attributes['enablePagination'] == 'true' && $grid_query->max_num_pages > 1) { | |
| 259 | + $loadmore_class = ''; | |
| 260 | + if ($attributes['loadMoreStyle']) { | |
| 261 | + $loadmore_class = $attributes['loadMoreStyle']; | |
| 262 | + } | |
| 263 | + if ($attributes['loadMoreAlignment']) { | |
| 264 | + $loadmore_class .= ' bs_blockspare_loadmore_' . $attributes['loadMoreAlignment']; | |
| 265 | + } | |
| 193 | 266 | |
| 194 | - | |
| 195 | 267 | |
| 196 | - /* Setup the featured image ID */ | |
| 197 | - $post_thumb_id = get_post_thumbnail_id($post_id); | |
| 198 | 268 | |
| 199 | - | |
| 200 | - if (!empty($attributes['imageSize'])) { | |
| 201 | - $post_thumb_size = $attributes['imageSize']; | |
| 269 | + | |
| 270 | + | |
| 271 | + ?> | |
| 272 | + <div class="bs_blockspare_loadmore blockspare-readmore-wrapper <?php echo esc_attr($loadmore_class); ?>" data-layout="<?php echo $layoutClass; ?>" block-name="<?php echo $blockName; ?>" data-page='2' blockspare-att=<?php echo "'" . esc_attr(wp_json_encode($attributes)) . "'"; ?> max-paged="<?php echo $grid_query->max_num_pages; ?>"> | |
| 273 | + <a href="#" class="blockspare-readmore"> | |
| 274 | + <div class="load-btn "><?php echo ($attributes['loadMoreText']); ?><span class="ajax-loader"></span></div> | |
| 275 | + </a> | |
| 276 | + </div><?php | |
| 202 | 277 | } |
| 278 | + ?> | |
| 279 | + </section> | |
| 203 | 280 | |
| 204 | - $content_order = false; | |
| 205 | - if($attributes['contentOrder']=='content-order-1' || $attributes['contentOrder']=='content-order-2'){ | |
| 206 | - $content_order =true; | |
| 207 | - } | |
| 208 | - if($blockName == 'full'){ | |
| 209 | - $content_order = true; | |
| 210 | - } | |
| 211 | - | |
| 212 | - if (!empty($attributes['imageSize'])) { | |
| 213 | - $post_thumb_size = $attributes['imageSize']; | |
| 214 | - } | |
| 215 | - | |
| 216 | - ?> | |
| 217 | - <figure class="blockspare-posts-block-post-img"> | |
| 218 | - <a href="<?php echo esc_url(get_permalink($post_id));?>" rel="bookmark" aria-hidden="true" | |
| 219 | - tabindex="-1"> | |
| 220 | - <?php | |
| 221 | - if(has_post_thumbnail($post_id)){ | |
| 222 | - | |
| 223 | - echo wp_kses_post(wp_get_attachment_image($post_thumb_id, $post_thumb_size)); | |
| 224 | - }else{?> | |
| 225 | - <div class="bs-no-thumbnail-img"> </div> | |
| 226 | - <?php } ?> | |
| 227 | - </a> | |
| 228 | - <?php if ($attributes['displayPostCategory'] && $content_order==true){?> | |
| 229 | - <!-- Category --> | |
| 230 | - <div class="<?php echo esc_attr($cat_class);?>"> | |
| 231 | - <?php blockspare_get_cat_tax_tags($attributes['taxType'],$post_id);?> | |
| 232 | - </div> | |
| 233 | - <!-- Category --> | |
| 234 | - <?php }?> | |
| 235 | - </figure> | |
| 236 | - <?php | |
| 237 | - | |
| 238 | - | |
| 239 | 281 | |
| 240 | - | |
| 282 | + | |
| 283 | + <?php } | |
| 284 | + wp_reset_postdata(); | |
| 241 | 285 | } |
| 242 | 286 | |
| 243 | -function blockspare_post_content($attributes,$post_id,$cat_class,$blockName=''){ | |
| 244 | - $content_order = false; | |
| 245 | - if($attributes['contentOrder']=='content-order-1' || $attributes['contentOrder']=='content-order-2'){ | |
| 246 | - $content_order =true; | |
| 287 | + | |
| 288 | +function blockspare_post_image($attributes, $post_id, $cat_class, $blockName = '', $count = '', $enableFeatureImage = '') | |
| 289 | +{ | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + /* Setup the featured image ID */ | |
| 295 | + $post_thumb_id = get_post_thumbnail_id($post_id); | |
| 296 | + | |
| 297 | + | |
| 298 | + if (!empty($attributes['imageSize'])) { | |
| 299 | + $post_thumb_size = $attributes['imageSize']; | |
| 300 | + } | |
| 301 | + | |
| 302 | + $content_order = false; | |
| 303 | + if ($attributes['contentOrder'] == 'content-order-1' || $attributes['contentOrder'] == 'content-order-2') { | |
| 304 | + $content_order = true; | |
| 305 | + } | |
| 306 | + if ($blockName == 'full') { | |
| 307 | + $content_order = true; | |
| 308 | + } | |
| 309 | + | |
| 310 | + $express_layout = false; | |
| 311 | + if (isset($attributes['expressList'])) { | |
| 312 | + if ($attributes['expressList'] == 'blockspare-posts-block-express-layout-3' || $attributes['expressList'] == 'blockspare-posts-block-express-layout-6') { | |
| 313 | + $express_layout = true; | |
| 247 | 314 | } |
| 248 | - if($blockName =='full'){ | |
| 249 | - $content_order =false; | |
| 315 | + } | |
| 316 | + | |
| 317 | + if ($blockName == 'express-post-list') { | |
| 318 | + if ($express_layout && $count <= 1) { | |
| 319 | + $post_thumb_size = $attributes['spotlightImageSize']; | |
| 320 | + } elseif ($express_layout == false && $count === 0) { | |
| 321 | + $post_thumb_size = $attributes['spotlightImageSize']; | |
| 322 | + } else { | |
| 323 | + $post_thumb_size = $attributes['imageSize']; | |
| 250 | 324 | } |
| 251 | - ?> | |
| 252 | - <div class="blockspare-posts-block-post-content <?php echo esc_attr($attributes['contentOrder']); ?> <?php echo esc_attr($attributes['titleOnHover'])?>"> | |
| 253 | - <div class="blockspare-posts-block-bg-overlay"></div> | |
| 254 | - <!-- blockspare-posts-block-post-grid-header --> | |
| 255 | - <header class="blockspare-posts-block-post-grid-header"> | |
| 256 | - <?php if ($attributes['displayPostCategory'] && $content_order ==false) {?> | |
| 257 | - <!-- Category --> | |
| 258 | - <div class="<?php echo esc_attr($cat_class);?>"> | |
| 259 | - <?php blockspare_get_cat_tax_tags($attributes['taxType'],$post_id);?> | |
| 260 | - </div> | |
| 261 | - <!-- Category --> | |
| 262 | - <?php }?> | |
| 263 | - <!-- blockspare-posts-block-post-grid-title --> | |
| 264 | - | |
| 265 | - <h4 class="blockspare-posts-block-post-grid-title"> | |
| 266 | - <a href="<?php echo esc_url(get_permalink($post_id)); ?>" class="blockspare-posts-block-title-link" | |
| 267 | - rel="bookmark"> | |
| 268 | - <span><?php echo get_the_title(); ?></span> | |
| 269 | - </a> | |
| 270 | - </h4> | |
| 271 | - | |
| 272 | - <!-- blockspare-posts-block-post-grid-title --> | |
| 325 | + } | |
| 273 | 326 | |
| 274 | - <!-- blockspare-posts-block-post-grid-byline --> | |
| 275 | - <div class="blockspare-posts-block-post-grid-byline"> | |
| 276 | - <!-- blockspare-posts-block-post-grid-author --> | |
| 277 | - <?php if (isset($attributes['displayPostAuthor']) && $attributes['displayPostAuthor'] =='true') {?> | |
| 278 | - <div class="blockspare-posts-block-post-grid-author"> | |
| 279 | - <!-- <a class="blockspare-posts-block-text-link" href="<?php echo esc_url(get_author_posts_url(get_the_author_meta('ID')));?>" | |
| 327 | + // if (!empty($attributes['imageSize'])) { | |
| 328 | + // $post_thumb_size = $attributes['imageSize']; | |
| 329 | + // } | |
| 330 | + | |
| 331 | + if ($attributes['enableFeatureImage'] == 'true') { | |
| 332 | + ?> | |
| 333 | + <figure class="blockspare-posts-block-post-img hover-child"> | |
| 334 | + <a href="<?php echo esc_url(get_permalink($post_id)); ?>" aria-label="<?php echo esc_attr(get_the_title($post_id)); ?>"> | |
| 335 | + <?php | |
| 336 | + if (has_post_thumbnail($post_id)) { | |
| 337 | + | |
| 338 | + echo wp_kses_post(wp_get_attachment_image($post_thumb_id, $post_thumb_size)); | |
| 339 | + } else { ?> | |
| 340 | + <div class="bs-no-thumbnail-img"> </div> | |
| 341 | + <?php } ?> | |
| 342 | + </a> | |
| 343 | + <?php if ($attributes['displayPostCategory'] == 'true' && $content_order == true) { ?> | |
| 344 | + <!-- Category --> | |
| 345 | + <div class="<?php echo esc_attr($cat_class); ?>"> | |
| 346 | + <?php blockspare_get_cat_tax_tags($attributes['taxType'], $post_id, $attributes['postType']); ?> | |
| 347 | + </div> | |
| 348 | + <!-- Category --> | |
| 349 | + <?php } ?> | |
| 350 | + </figure> | |
| 351 | + <?php | |
| 352 | + } | |
| 353 | +} | |
| 354 | + | |
| 355 | +function blockspare_post_content($attributes, $post_id, $cat_class, $blockName = '', $className = '') | |
| 356 | +{ | |
| 357 | + $content_order = false; | |
| 358 | + if ($attributes['contentOrder'] == 'content-order-1' || $attributes['contentOrder'] == 'content-order-2') { | |
| 359 | + $content_order = true; | |
| 360 | + } | |
| 361 | + if ($blockName == 'full') { | |
| 362 | + $content_order = false; | |
| 363 | + } | |
| 364 | + | |
| 365 | + ?> | |
| 366 | + <div class="blockspare-posts-block-post-content <?php echo esc_attr($className); ?> <?php echo esc_attr($attributes['contentOrder']); ?> <?php echo esc_attr($attributes['titleOnHover']) ?>"> | |
| 367 | + <div class="blockspare-posts-block-bg-overlay"></div> | |
| 368 | + <!-- blockspare-posts-block-post-grid-header --> | |
| 369 | + <header class="blockspare-posts-block-post-grid-header"> | |
| 370 | + <!--display category when feature image is disable --> | |
| 371 | + <?php if ($attributes['displayPostCategory'] == 'true' && $attributes['enableFeatureImage'] != 'true') { ?> | |
| 372 | + <!-- Category --> | |
| 373 | + <div class="<?php echo esc_attr($cat_class); ?>"> | |
| 374 | + <?php blockspare_get_cat_tax_tags($attributes['taxType'], $post_id, $attributes['postType']); ?> | |
| 375 | + </div> | |
| 376 | + <!-- Category --> | |
| 377 | + <?php } ?> | |
| 378 | + <!--display category when feature image is enable--> | |
| 379 | + <?php if ($attributes['displayPostCategory'] == 'true' && $attributes['enableFeatureImage'] == 'true' && $content_order == false) { ?> | |
| 380 | + <!-- Category --> | |
| 381 | + <div class="<?php echo esc_attr($cat_class); ?>"> | |
| 382 | + <?php blockspare_get_cat_tax_tags($attributes['taxType'], $post_id, $attributes['postType']); ?> | |
| 383 | + </div> | |
| 384 | + <!-- Category --> | |
| 385 | + <?php } ?> | |
| 386 | + <!-- blockspare-posts-block-post-grid-title --> | |
| 387 | + <?php | |
| 388 | + if (isset($attributes['displayPostTitle']) && $attributes['displayPostTitle'] == 'true') { ?> | |
| 389 | + <h2 class="blockspare-posts-block-post-grid-title"> | |
| 390 | + <a href="<?php echo esc_url(get_permalink($post_id)); ?>" class="blockspare-posts-block-title-link" | |
| 391 | + rel="bookmark"> | |
| 392 | + <span><?php echo get_the_title(); ?></span> | |
| 393 | + </a> | |
| 394 | + </h2> | |
| 395 | + <?php } ?> | |
| 396 | + <!-- blockspare-posts-block-post-grid-title --> | |
| 397 | + | |
| 398 | + <!-- blockspare-posts-block-post-grid-byline --> | |
| 399 | + <div class="blockspare-posts-block-post-grid-byline"> | |
| 400 | + <!-- blockspare-posts-block-post-grid-author --> | |
| 401 | + <?php if (isset($attributes['displayPostAuthor']) && $attributes['displayPostAuthor'] == 'true') { ?> | |
| 402 | + <div class="blockspare-posts-block-post-grid-author"> | |
| 403 | + <!-- <a class="blockspare-posts-block-text-link" href="<?php echo esc_url(get_author_posts_url(get_the_author_meta('ID'))); ?>" | |
| 280 | 404 | itemprop="url" rel="author"> |
| 281 | 405 | <span itemprop="name"> |
| 282 | - <i class="<?php echo esc_attr($attributes['authorIcon']);?>"></i> | |
| 283 | - <?php echo esc_html(get_the_author_meta('display_name', get_the_author_meta('ID')));?> | |
| 406 | + <i class="<?php echo esc_attr($attributes['authorIcon']); ?>"></i> | |
| 407 | + <?php echo (get_the_author_meta('display_name', get_the_author_meta('ID'))); ?> | |
| 284 | 408 | </span> |
| 285 | 409 | </a> --> |
| 286 | - <?php | |
| 287 | - $author_id = get_post_field( 'post_author', $post_id ); | |
| 288 | - $blockspare_get_multiauthor= new BlocksapreMultiAuthorForFrontend(); | |
| 289 | - $blockspare_get_multiauthor->blockspare_front_by_author($post_id,$attributes['authorIcon'],$author_id); | |
| 290 | - ?> | |
| 291 | - </div> | |
| 292 | - <?php }?> | |
| 293 | - <!-- blockspare-posts-block-post-grid-author --> | |
| 410 | + <?php | |
| 411 | + $author_id = get_post_field('post_author', $post_id); | |
| 412 | + $blockspare_get_multiauthor = new BlocksapreMultiAuthorForFrontend(); | |
| 413 | + $blockspare_get_multiauthor->blockspare_front_by_author($post_id, $attributes['authorIcon'], $author_id); ?> | |
| 414 | + </div> | |
| 415 | + <?php } ?> | |
| 416 | + <!-- blockspare-posts-block-post-grid-author --> | |
| 294 | 417 | |
| 295 | - <!-- blockspare-posts-block-post-grid-date --> | |
| 296 | - <?php if(isset($attributes['displayPostDate']) && $attributes['displayPostDate'] =='true') {?> | |
| 297 | - <time datetime="<?php echo esc_attr(get_the_date('c', $post_id));?>" | |
| 298 | - class="blockspare-posts-block-post-grid-date" itemprop="datePublished"> | |
| 299 | - <i class="<?php echo esc_attr($attributes['dateIcon']);?>"></i> | |
| 300 | - <?php echo esc_html(get_the_date('', $post_id));?> | |
| 301 | - </time> | |
| 302 | - <?php }?> | |
| 303 | - <!-- blockspare-posts-block-post-grid-date --> | |
| 418 | + <!-- blockspare-posts-block-post-grid-date --> | |
| 419 | + <?php if (isset($attributes['displayPostDate']) && $attributes['displayPostDate'] == 'true') { ?> | |
| 420 | + <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 $bs_meta_date = get_the_date('', $post_id); | |
| 421 | + echo trim($bs_meta_date); ?></time> | |
| 422 | + <?php } ?> | |
| 423 | + <!-- blockspare-posts-block-post-grid-date --> | |
| 304 | 424 | |
| 305 | - <!-- comment_count --> | |
| 306 | - <?php if($attributes['enableComment'] =='true'){?> | |
| 307 | - <span class="comment_count"> | |
| 308 | - <i class='<?php echo esc_attr($attributes['commentIcon']);?>'></i> | |
| 309 | - <?php echo esc_html(get_comments_number($post_id)); ?> | |
| 310 | - </span> | |
| 311 | - <?php }?> | |
| 312 | - <!-- comment_count --> | |
| 313 | - </div> | |
| 314 | - <!-- blockspare-posts-block-post-grid-byline --> | |
| 315 | - </header> | |
| 316 | - <!-- blockspare-posts-block-post-grid-header --> | |
| 425 | + <!-- comment_count --> | |
| 426 | + <?php if ($attributes['enableComment'] == 'true') { ?> | |
| 427 | + <span class="comment_count"><i class='<?php echo esc_attr($attributes['commentIcon']); ?>' aria-hidden="true"></i><?php echo trim(esc_html(get_comments_number($post_id))); ?></span> | |
| 428 | + <?php } ?> | |
| 429 | + <!-- comment_count --> | |
| 430 | + </div> | |
| 431 | + <!-- blockspare-posts-block-post-grid-byline --> | |
| 432 | + </header> | |
| 433 | + <!-- blockspare-posts-block-post-grid-header --> | |
| 317 | 434 | |
| 318 | - <?php | |
| 319 | - $excerpt = blockspare_excerpt ($post_id,$attributes['excerptLength']); | |
| 320 | - $new_excerpt = apply_filters( 'the_excerpt', $excerpt );?> | |
| 321 | - <!-- blockspare-posts-block-post-grid-excerpt --> | |
| 322 | - <?php if ($attributes['displayPostExcerpt'] && $new_excerpt != null || isset($attributes['displayPostLink'])) { ?> | |
| 323 | - <div class="blockspare-posts-block-post-grid-excerpt"> | |
| 324 | - <!-- blockspare-posts-block-post-grid-excerpt-content --> | |
| 325 | - <?php if (isset($attributes['displayPostExcerpt']) && $attributes['displayPostExcerpt'] =='true') { ?> | |
| 326 | - <div class="blockspare-posts-block-post-grid-excerpt-content"> | |
| 327 | - <?php echo wp_kses_post($excerpt); ?> | |
| 328 | - </div> | |
| 329 | - <?php }?> | |
| 330 | - <!-- blockspare-posts-block-post-grid-excerpt-content --> | |
| 331 | - <!-- blockspare-posts-block-post-grid-more-link --> | |
| 332 | - <?php if (isset($attributes['displayPostLink']) && $attributes['displayPostLink'] =='true') { ?> | |
| 333 | - <p> | |
| 334 | - <a class="blockspare-posts-block-post-grid-more-link blockspare-posts-block-text-link" | |
| 335 | - href="<?php echo esc_url(get_permalink($post_id)); ?>" rel="bookmark"> | |
| 336 | - <span><?php echo esc_html($attributes['readMoreText']); ?></span> | |
| 337 | - </a> | |
| 338 | - </p> | |
| 339 | - <?php }?> | |
| 340 | - <!-- blockspare-posts-block-post-grid-more-link --> | |
| 341 | - </div> | |
| 342 | - <?php }?> | |
| 343 | - <!-- blockspare-posts-block-post-grid-excerpt --> | |
| 344 | - | |
| 345 | - </div> | |
| 435 | + <?php | |
| 436 | + $excerpt = blockspare_excerpt($post_id, $attributes['excerptLength']); | |
| 437 | + $new_excerpt = apply_filters('the_excerpt', $excerpt); ?> | |
| 438 | + <!-- blockspare-posts-block-post-grid-excerpt --> | |
| 439 | + <?php if ($attributes['displayPostExcerpt'] == 'true' && $new_excerpt != null) { ?> | |
| 440 | + <div class="blockspare-posts-block-post-grid-excerpt"> | |
| 441 | + <!-- blockspare-posts-block-post-grid-excerpt-content --> | |
| 442 | + <?php if (isset($attributes['displayPostExcerpt']) && $attributes['displayPostExcerpt'] == 'true') { ?> | |
| 443 | + <div class="blockspare-posts-block-post-grid-excerpt-content"> | |
| 444 | + <?php echo wp_kses_post($excerpt); ?> | |
| 445 | + </div> | |
| 446 | + <?php } ?> | |
| 447 | + <!-- blockspare-posts-block-post-grid-excerpt-content --> | |
| 448 | + <!-- blockspare-posts-block-post-grid-more-link --> | |
| 449 | + <?php if (isset($attributes['displayPostLink']) && $attributes['displayPostLink'] == 'true') { ?> | |
| 450 | + <p> | |
| 451 | + <a | |
| 452 | + class="blockspare-posts-block-post-grid-more-link blockspare-posts-block-text-link" | |
| 453 | + href="<?php echo esc_url(get_permalink($post_id)); ?>" | |
| 454 | + aria-label="<?php echo sprintf(esc_attr__('Read more about %s', 'blockspare'), esc_html(get_the_title($post_id))); ?>"> | |
| 455 | + <span aria-hidden="true"><?php echo esc_html($attributes['readMoreText']); ?></span> | |
| 456 | + </a> | |
| 457 | + | |
| 458 | + </p> | |
| 459 | + <?php } ?> | |
| 460 | + <!-- blockspare-posts-block-post-grid-more-link --> | |
| 461 | + </div> | |
| 462 | + <?php } ?> | |
| 463 | + <!-- blockspare-posts-block-post-grid-excerpt --> | |
| 464 | + | |
| 465 | + </div> | |
| 346 | 466 | <?php } |
| 347 | 467 | |
| 348 | 468 | |
| 349 | -function bscheckFontfamily($fontFamily){ | |
| 350 | - | |
| 351 | - $fonts = ''; | |
| 352 | - if($fontFamily!='Default' && $fontFamily !="undefined"){ | |
| 353 | - $fonts = 'font-family:'.$fontFamily; | |
| 354 | - } | |
| 355 | - return $fonts; | |
| 469 | +function bscheckFontfamily($fontFamily) | |
| 470 | +{ | |
| 356 | 471 | |
| 357 | - } | |
| 472 | + $fonts = ''; | |
| 473 | + if ($fontFamily != 'Default' && $fontFamily != "undefined") { | |
| 474 | + $fonts = 'font-family:' . $fontFamily; | |
| 475 | + } | |
| 476 | + return $fonts; | |
| 477 | +} | |
| 358 | 478 | |
| 359 | 479 | |
| 360 | -function blockspare_excerpt($post_id,$length=''){ | |
| 361 | - $excerpt = get_post_field( | |
| 362 | - 'post_excerpt', | |
| 363 | - $post_id, | |
| 364 | - 'display' | |
| 480 | +function bscheckFontfamilyWeight($fontFamilyWeight) | |
| 481 | +{ | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + $fontsweight = ''; | |
| 486 | + if ($fontFamilyWeight != '' && $fontFamilyWeight != "undefined") { | |
| 487 | + $fontsweight = 'font-weight:' . $fontFamilyWeight; | |
| 488 | + } | |
| 489 | + return $fontsweight; | |
| 490 | +} | |
| 491 | + | |
| 492 | + | |
| 493 | +function blockspare_excerpt($post_id, $length = '') | |
| 494 | +{ | |
| 495 | + $excerpt = get_post_field( | |
| 496 | + 'post_excerpt', | |
| 497 | + $post_id, | |
| 498 | + 'display' | |
| 499 | + ); | |
| 500 | + $excerpt = preg_replace('~^(\s*(?: )?)*~i', '', $excerpt); | |
| 501 | + if (empty($excerpt)) { | |
| 502 | + $excerpt = preg_replace( | |
| 503 | + array( | |
| 504 | + '/\<figcaption>.*\<\/figcaption>/', | |
| 505 | + '/\[caption.*\[\/caption\]/', | |
| 506 | + '`[[^]]*]`' | |
| 507 | + ), | |
| 508 | + '', | |
| 509 | + get_the_content() | |
| 365 | 510 | ); |
| 366 | - | |
| 367 | - if ( empty( $excerpt ) ) { | |
| 368 | - $excerpt = preg_replace( | |
| 369 | - array( | |
| 370 | - '/\<figcaption>.*\<\/figcaption>/', | |
| 371 | - '/\[caption.*\[\/caption\]/', | |
| 372 | - ), | |
| 373 | - '', | |
| 374 | - get_the_content() | |
| 375 | - ); | |
| 376 | - } | |
| 377 | - | |
| 378 | - // Trim the excerpt if necessary. | |
| 379 | - if ( isset( $length ) ) { | |
| 380 | - $excerpt = wp_trim_words( | |
| 381 | - $excerpt, | |
| 382 | - $length | |
| 383 | - ); | |
| 384 | - } | |
| 511 | + } | |
| 385 | 512 | |
| 386 | - return $excerpt; | |
| 387 | -} | |
| 513 | + // Trim the excerpt if necessary. | |
| 514 | + if (isset($length)) { | |
| 515 | + $excerpt = wp_trim_words( | |
| 516 | + $excerpt, | |
| 517 | + $length | |
| 518 | + ); | |
| 519 | + } | |
| 520 | + | |
| 521 | + return $excerpt; | |
| 522 | +} | |