| 1 |
<?php |
| 2 |
function bs_load_more() |
| 3 |
{ |
| 4 |
|
| 5 |
|
| 6 |
check_ajax_referer('blockspare-load-more-nonce', 'nonce'); |
| 7 |
$bs_attributes = $_GET['postData']; |
| 8 |
$paged = $_GET['bspage']; |
| 9 |
$block_name = $_GET['blockName']; |
| 10 |
$updated_current_page = $paged + 1; |
| 11 |
$layoutClass = $_GET['layoutClass']; |
| 12 |
|
| 13 |
if (isset($bs_attributes['categories']) && ! empty($bs_attributes['categories']) && is_array($bs_attributes['categories'])) { |
| 14 |
$categories = array(); |
| 15 |
$i = 1; |
| 16 |
foreach ($bs_attributes['categories'] as $key => $value) { |
| 17 |
$categories[] = $value['value']; |
| 18 |
} |
| 19 |
} else { |
| 20 |
$categories = array(); |
| 21 |
} |
| 22 |
|
| 23 |
if (isset($bs_attributes['tags']) && ! empty($bs_attributes['tags']) && is_array($bs_attributes['tags'])) { |
| 24 |
$tags = array(); |
| 25 |
$i = 1; |
| 26 |
foreach ($bs_attributes['tags'] as $key => $value) { |
| 27 |
$tags[] = $value['value']; |
| 28 |
} |
| 29 |
} else { |
| 30 |
$tags = array(); |
| 31 |
} |
| 32 |
|
| 33 |
/* Setup the query */ |
| 34 |
|
| 35 |
$query_args = array( |
| 36 |
'posts_per_page' => $bs_attributes['postsToShow'], |
| 37 |
'post_status' => 'publish', |
| 38 |
'offset' => ($bs_attributes['enablePagination'] == 'true') ? '' : $bs_attributes['offset'], |
| 39 |
'order' => $bs_attributes['order'], |
| 40 |
'orderby' => $bs_attributes['orderBy'], |
| 41 |
'post_type' => $bs_attributes['postType'], |
| 42 |
'paged' => $paged |
| 43 |
); |
| 44 |
//wp_send_json_success($query_args);die; |
| 45 |
if ('post' != $bs_attributes['postType']) { |
| 46 |
|
| 47 |
$tax_type = $bs_attributes['taxType']; |
| 48 |
if ($tax_type) { |
| 49 |
if (!empty($categories)) { |
| 50 |
$query_args['tax_query'][] = array( |
| 51 |
'taxonomy' => (isset($tax_type)) ? $tax_type : 'category', |
| 52 |
'field' => 'id', |
| 53 |
'terms' => $categories, |
| 54 |
'operator' => 'IN', |
| 55 |
); |
| 56 |
} |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
if ('post' == $bs_attributes['postType']) { |
| 61 |
|
| 62 |
$tax_type = $bs_attributes['taxType']; |
| 63 |
if ($tax_type) { |
| 64 |
if (!empty($categories)) { |
| 65 |
$query_args['tax_query'][] = array( |
| 66 |
'taxonomy' => (isset($tax_type)) ? $tax_type : 'category', |
| 67 |
'field' => 'id', |
| 68 |
'terms' => $categories, |
| 69 |
'operator' => 'IN', |
| 70 |
); |
| 71 |
} else { |
| 72 |
|
| 73 |
$taxonomy = $tax_type; // this is the name of the taxonomy |
| 74 |
$terms = get_terms($taxonomy); |
| 75 |
if (!empty($terms)) { |
| 76 |
$query_args['tax_query'][] = array( |
| 77 |
'taxonomy' => (isset($tax_type)) ? $tax_type : 'category', |
| 78 |
'field' => 'slug', |
| 79 |
'terms' => wp_list_pluck($terms, 'slug') |
| 80 |
|
| 81 |
); |
| 82 |
} |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 86 |
if ($bs_attributes['taxType'] == 'category') { |
| 87 |
$query_args['category__in'] = $categories; |
| 88 |
} |
| 89 |
if ($bs_attributes['taxType'] == 'post_tag') { |
| 90 |
$query_args['tag__in'] = $tags; |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
// if($bs_attributes['taxType'] !='category' && $bs_attributes['taxType'] != 'post_tag'){ |
| 95 |
|
| 96 |
// $tax_type = $bs_attributes['taxType']; |
| 97 |
// if ( $tax_type ) { |
| 98 |
// $query_args['tax_query'][] = array( |
| 99 |
// 'taxonomy' => ( isset( $tax_type ) ) ? $tax_type : 'category', |
| 100 |
// 'field' => 'id', |
| 101 |
// 'terms' => $categories, |
| 102 |
// 'operator' => 'IN' , |
| 103 |
// ); |
| 104 |
// } |
| 105 |
// } |
| 106 |
/* Setup the query */ |
| 107 |
$grid_query = new WP_Query($query_args); |
| 108 |
|
| 109 |
ob_start(); |
| 110 |
while ($grid_query->have_posts()) { |
| 111 |
$grid_query->the_post(); |
| 112 |
|
| 113 |
/* Setup the post ID */ |
| 114 |
$post_id = get_the_ID(); |
| 115 |
|
| 116 |
|
| 117 |
/* Setup the featured image ID */ |
| 118 |
$post_thumb_id = get_post_thumbnail_id($post_id); |
| 119 |
|
| 120 |
$has_img_class = ''; |
| 121 |
|
| 122 |
if (!$post_thumb_id) { |
| 123 |
$has_img_class = "post-has-no-image "; |
| 124 |
} |
| 125 |
|
| 126 |
if (isset($bs_attributes['full'])) { |
| 127 |
if ($bs_attributes['full'] == 'blockspare-posts-block-full-layout-4') { |
| 128 |
$bs_attributes['enableEqualHeight'] = false; |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
if ($bs_attributes['enableEqualHeight']) { |
| 134 |
$has_img_class .= 'bs-has-equal-height'; |
| 135 |
} |
| 136 |
$post_classes = ''; |
| 137 |
$contentOrderClass = ''; |
| 138 |
if ($block_name = 'tile') { |
| 139 |
if ($bs_attributes['contentOrder'] == 'content-order-1') { |
| 140 |
$contentOrderClass .= 'contentorderone'; |
| 141 |
} |
| 142 |
if ($bs_attributes['contentOrder'] == 'content-order-2') { |
| 143 |
$contentOrderClass .= 'contentordertwo'; |
| 144 |
} |
| 145 |
} else { |
| 146 |
if ($bs_attributes['contentOrder'] == 'content-order-5') { |
| 147 |
$contentOrderClass .= 'contentorderfive'; |
| 148 |
} |
| 149 |
if ($bs_attributes['contentOrder'] == 'content-order-6') { |
| 150 |
$contentOrderClass .= 'contentordersix'; |
| 151 |
} |
| 152 |
if ($bs_attributes['enableEqualHeight']) { |
| 153 |
$contentOrderClass .= 'bs-has-equal-height'; |
| 154 |
} |
| 155 |
if ($bs_attributes['enableBackgroundColor']) { |
| 156 |
$post_classes .= ' has-background'; |
| 157 |
} |
| 158 |
} |
| 159 |
|
| 160 |
/* Setup the post classes */ |
| 161 |
$post_classes = 'blockspare-posts-block-post-single blockspare-hover-item ' . $contentOrderClass; |
| 162 |
|
| 163 |
$className = ''; |
| 164 |
if (isset($bs_attributes['full'])) { |
| 165 |
if ($bs_attributes['full'] == 'blockspare-posts-block-full-layout-6') { |
| 166 |
$post_classes .= ' blockspare-hover-child'; |
| 167 |
$className .= 'hover-child'; |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
/* Add sticky class */ |
| 173 |
if (is_sticky($post_id)) { |
| 174 |
$post_classes .= ' sticky'; |
| 175 |
} else { |
| 176 |
$post_classes .= null; |
| 177 |
} |
| 178 |
if ($layoutClass) { |
| 179 |
$post_classes .= ' has-background'; |
| 180 |
} else { |
| 181 |
$post_classes .= ' blockspare-hover-child'; |
| 182 |
} |
| 183 |
$category_class = 'blockspare-posts-block-post-category'; |
| 184 |
|
| 185 |
if ($bs_attributes['categoryLayoutOption'] == 'none') { |
| 186 |
$category_class .= ' has-no-category-style'; |
| 187 |
} |
| 188 |
if (!empty($bs_attributes['imageSize'])) { |
| 189 |
$post_thumb_size = $bs_attributes['imageSize']; |
| 190 |
} |
| 191 |
|
| 192 |
$blockName = $_GET['blockName']; |
| 193 |
|
| 194 |
?> |
| 195 |
|
| 196 |
<?php if ($blockName === 'post-tile-masonry' || $blockName === 'post-grid-masonry') { ?> |
| 197 |
<div class="blockspare-posts-masonry-item-wrapper masonry-brick"> |
| 198 |
|
| 199 |
<?php } |
| 200 |
|
| 201 |
?> |
| 202 |
<div id="<?php echo esc_attr($post_id); ?>" class="<?php echo esc_attr($post_classes) . ' ' . $has_img_class; ?>"> |
| 203 |
<?php |
| 204 |
|
| 205 |
if ($blockName == 'tile' || $blockName == 'post-tile-masonry') { |
| 206 |
|
| 207 |
|
| 208 |
blockspare_post_tile_img($post_id, $category_class, $bs_attributes, $post_thumb_id, $post_thumb_size); |
| 209 |
blockspare_post_tile_content($bs_attributes, $post_id, $category_class, $className); |
| 210 |
} else if ($blockName == 'express') { |
| 211 |
|
| 212 |
blockspare_express_post_image($bs_attributes, $post_id, $category_class, 'express', $className, 5); |
| 213 |
blockspare_express_post_content($bs_attributes, $post_id, $category_class, 'express', $className, 5); |
| 214 |
} else if ($blockName == 'express-post-list') { |
| 215 |
|
| 216 |
blockspare_express_list_post_image($bs_attributes, $post_id, $category_class, 'express', $className, 5); |
| 217 |
blockspare_express_list_post_content($bs_attributes, $post_id, $category_class, 'express', $className, 5); |
| 218 |
} else { |
| 219 |
|
| 220 |
blockspare_post_image($bs_attributes, $post_id, $category_class, $blockName, $bs_attributes['enableFeatureImage']); |
| 221 |
blockspare_post_content($bs_attributes, $post_id, $category_class, $blockName, $className); |
| 222 |
} |
| 223 |
?> |
| 224 |
</div> |
| 225 |
<?php if ($blockName == 'tile' || $blockName == 'post-grid-masonry') { ?> |
| 226 |
</div> |
| 227 |
<?php } ?> |
| 228 |
<?php } |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
$maxpages = $_GET['maxnumpages']; |
| 233 |
if ($maxpages > $paged) { |
| 234 |
$blockspare_output['more_post'] = true; |
| 235 |
} else { |
| 236 |
$blockspare_output['more_post'] = false; |
| 237 |
} |
| 238 |
$blockspare_output['current_page'] = $updated_current_page; |
| 239 |
$blockspare_output['content'][] = ob_get_clean(); |
| 240 |
wp_send_json_success($blockspare_output); |
| 241 |
|
| 242 |
wp_die(); |
| 243 |
} |
| 244 |
|
| 245 |
add_action('wp_ajax_bs_load_more', 'bs_load_more'); |
| 246 |
add_action('wp_ajax_nopriv_bs_load_more', 'bs_load_more'); |
| 247 |
|