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