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