| 1 |
<?php |
| 2 |
|
| 3 |
if(!function_exists('blockspare_render_block_core_latest_posts_grid')){ |
| 4 |
function blockspare_render_block_core_latest_posts_grid($attributes) |
| 5 |
{ |
| 6 |
|
| 7 |
if($attributes['enablePagination']){ |
| 8 |
wp_enqueue_script('blockspare-pagination-js'); |
| 9 |
} |
| 10 |
ob_start(); |
| 11 |
$unq_class = mt_rand(100000,999999); |
| 12 |
$blockuniqueclass = ''; |
| 13 |
|
| 14 |
if(!empty($attributes['uniqueClass'])){ |
| 15 |
$blockuniqueclass = $attributes['uniqueClass']; |
| 16 |
}else{ |
| 17 |
$blockuniqueclass = 'blockspare-posts-block-list-'.$unq_class; |
| 18 |
} |
| 19 |
|
| 20 |
$block_class = 'blockspare-posts-block-is-grid'.' has-gutter-'.$attributes['gutterSpace'].' column-'.$attributes['columns']; |
| 21 |
$design = $attributes['grid']; |
| 22 |
$blockName= 'post-grid'; |
| 23 |
$layoutClass= false; |
| 24 |
if($attributes['grid'] != 'blockspare-posts-block-grid-layout-4' && $attributes['grid'] != 'blockspare-posts-block-grid-layout-5' && $attributes['grid'] != 'blockspare-posts-block-grid-layout-6') { |
| 25 |
$layoutClass= true; |
| 26 |
} |
| 27 |
$alignclass = blockspare_checkalignment($attributes['align']); |
| 28 |
$class = "wp-block-blockspare-posts-block-blockspare-posts-block-latest-posts align".$alignclass." ".$attributes['blockHoverEffect']." ".$attributes['imageHoverEffect'] ; |
| 29 |
|
| 30 |
if (isset($attributes['className'])) { |
| 31 |
$class .= ' ' . $attributes['className']; |
| 32 |
} |
| 33 |
|
| 34 |
if( $attributes['animation']){ |
| 35 |
$class .=' blockspare-block-animation'; |
| 36 |
} |
| 37 |
$class .= ' ' . $blockuniqueclass; |
| 38 |
|
| 39 |
?> |
| 40 |
<div class="<?php echo esc_attr($class);?>" blockspare-animation=<?php echo esc_attr( $attributes['animation'] )?>> |
| 41 |
<?php |
| 42 |
echo latest_posts_style_control_grid($blockuniqueclass ,$attributes); |
| 43 |
blockspare_query_loop_and_wrapper($attributes,$block_class,$design,$blockName,$layoutClass); |
| 44 |
?> |
| 45 |
</div> |
| 46 |
<?php |
| 47 |
return ob_get_clean(); |
| 48 |
|
| 49 |
|
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Registers the post grid block on server |
| 55 |
*/ |
| 56 |
if(!function_exists('blockspare_register_block_core_latest_posts_grid')){ |
| 57 |
function blockspare_register_block_core_latest_posts_grid() |
| 58 |
{ |
| 59 |
|
| 60 |
if (!function_exists('register_block_type')) { |
| 61 |
return; |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
ob_start(); |
| 66 |
include BLOCKSPARE_PLUGIN_DIR . 'inc/latest-post-block/posts-grid/block.json'; |
| 67 |
$metadata = json_decode(ob_get_clean(), true); |
| 68 |
|
| 69 |
/* Block attributes */ |
| 70 |
register_block_type( |
| 71 |
'blockspare/blockspare-latest-posts-grid', |
| 72 |
array( |
| 73 |
'attributes' =>$metadata['attributes'], |
| 74 |
'render_callback' => 'blockspare_render_block_core_latest_posts_grid', |
| 75 |
) |
| 76 |
); |
| 77 |
} |
| 78 |
|
| 79 |
add_action('init', 'blockspare_register_block_core_latest_posts_grid'); |
| 80 |
} |
| 81 |
|
| 82 |
if(!function_exists('latest_posts_style_control_grid')){ |
| 83 |
function latest_posts_style_control_grid($blockuniqueclass ,$attributes){ |
| 84 |
|
| 85 |
|
| 86 |
$block_content =''; |
| 87 |
$block_content .= '<style type="text/css">'; |
| 88 |
$block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-wrap{ |
| 89 |
margin-top:' . $attributes['marginTop'] . 'px; |
| 90 |
margin-bottom:' . $attributes['marginBottom'] . 'px; |
| 91 |
margin-left:' . $attributes['marginLeft'] . 'px; |
| 92 |
margin-right:' . $attributes['marginRight'] . 'px; |
| 93 |
}'; |
| 94 |
|
| 95 |
$block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-content{ |
| 96 |
padding-top:' . $attributes['contentPaddingTop'] . 'px; |
| 97 |
padding-right:' . $attributes['contentPaddingRight'] . 'px; |
| 98 |
padding-bottom:' . $attributes['contentPaddingBottom'] . 'px; |
| 99 |
padding-left:' . $attributes['contentPaddingLeft'] . 'px; |
| 100 |
}'; |
| 101 |
|
| 102 |
blockspare_posts_category_style( |
| 103 |
$block_content, |
| 104 |
$attributes, |
| 105 |
$blockuniqueclass, |
| 106 |
$attributes['categoryTextColor'], |
| 107 |
$attributes['categoryBackgroundColor'], |
| 108 |
$attributes['categoryBorderColor'], |
| 109 |
$attributes['secondCategoryTextColor'], |
| 110 |
$attributes['secondCategoryBackgroundColor'], |
| 111 |
$attributes['secondCategoryBorderColor'], |
| 112 |
$attributes['thirdCategoryTextColor'], |
| 113 |
$attributes['thirdCategoryBackgroundColor'], |
| 114 |
$attributes['thirdCategoryBorderColor'], |
| 115 |
); |
| 116 |
|
| 117 |
$block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-byline{ |
| 118 |
margin-top:' . $attributes['metaMarginTop'] . 'px' . '; |
| 119 |
margin-bottom:' . $attributes['metaMarginBottom'] . 'px' . '; |
| 120 |
margin-left:' . $attributes['metaMarginLeft'] . 'px' . '; |
| 121 |
margin-right:' . $attributes['metaMarginRight'] . 'px' . '; |
| 122 |
}'; |
| 123 |
|
| 124 |
$block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-more-link{ |
| 125 |
margin-top:' . $attributes['moreLinkMarginTop'] . 'px' . '; |
| 126 |
margin-bottom:' . $attributes['moreLinkMarginBottom'] . 'px' . '; |
| 127 |
margin-left:' . $attributes['moreLinkMarginLeft'] . 'px' . '; |
| 128 |
margin-right:' . $attributes['moreLinkMarginRight'] . 'px' . '; |
| 129 |
}'; |
| 130 |
|
| 131 |
$block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-title a span{ |
| 132 |
color: ' . $attributes['postTitleColor'] . '; |
| 133 |
}'; |
| 134 |
|
| 135 |
$block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-author a span{ |
| 136 |
color:' . $attributes['linkColor'] . '; |
| 137 |
}'; |
| 138 |
|
| 139 |
|
| 140 |
$block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-more-link span{ |
| 141 |
color:' . $attributes['linkColor'] . '; |
| 142 |
}'; |
| 143 |
|
| 144 |
$block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-date{ |
| 145 |
color:' . $attributes['generalColor'] . '; |
| 146 |
}'; |
| 147 |
|
| 148 |
$block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-excerpt-content{ |
| 149 |
color:' . $attributes['generalColor'] . '; |
| 150 |
}'; |
| 151 |
$block_content .= ' .' . $blockuniqueclass . ' .comment_count{ |
| 152 |
color:' . $attributes['generalColor'] . '; |
| 153 |
}'; |
| 154 |
|
| 155 |
$block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-title{ |
| 156 |
margin-top:' . $attributes['titleMarginTop'] . 'px' . '; |
| 157 |
margin-bottom:' . $attributes['titleMarginBottom'] . 'px' . '; |
| 158 |
margin-left:' . $attributes['titleMarginLeft'] . 'px' . '; |
| 159 |
margin-right:' . $attributes['titleMarginRight'] . 'px' . '; |
| 160 |
}'; |
| 161 |
|
| 162 |
$block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-excerpt-content{ |
| 163 |
margin-top:' . $attributes['exceprtMarginTop'] . 'px' . '; |
| 164 |
margin-bottom:' . $attributes['exceprtMarginBottom'] . 'px' . '; |
| 165 |
margin-left:' . $attributes['exceprtMarginLeft'] . 'px' . '; |
| 166 |
margin-right:' . $attributes['exceprtMarginRight'] . 'px' . '; |
| 167 |
}'; |
| 168 |
|
| 169 |
$layoutstyle = explode('-',$attributes['grid']); |
| 170 |
if($layoutstyle[5] >3){ |
| 171 |
$block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-single .blockspare-posts-block-post-img { |
| 172 |
border-radius:' . $attributes['borderRadius'] . 'px'.'; |
| 173 |
}'; |
| 174 |
if($attributes['enableBoxShadow']){ |
| 175 |
$block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-single .blockspare-posts-block-post-img { |
| 176 |
box-shadow: ' . $attributes['xOffset'] . 'px ' . $attributes['yOffset'] . 'px ' . $attributes['blur'] . 'px ' . $attributes['spread'] . 'px ' . $attributes['shadowColor'] . '; |
| 177 |
}'; |
| 178 |
} |
| 179 |
}else{ |
| 180 |
$block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-single{ |
| 181 |
border-radius:' . $attributes['borderRadius'] . 'px'.'; |
| 182 |
background-color:'.$attributes['backGroundColor'].' |
| 183 |
}'; |
| 184 |
|
| 185 |
if($attributes['enableBoxShadow']){ |
| 186 |
$block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-single{ |
| 187 |
box-shadow: ' . $attributes['xOffset'] . 'px ' . $attributes['yOffset'] . 'px ' . $attributes['blur'] . 'px ' . $attributes['spread'] . 'px ' . $attributes['shadowColor'] . '; |
| 188 |
}'; |
| 189 |
} |
| 190 |
} |
| 191 |
|
| 192 |
//Title Hover |
| 193 |
|
| 194 |
if($attributes['titleOnHover']=='lpc-title-hover') { |
| 195 |
$block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-content .blockspare-posts-block-title-link:hover span{ |
| 196 |
color: ' . $attributes['titleOnHoverColor'] . '; |
| 197 |
}'; |
| 198 |
} |
| 199 |
|
| 200 |
if($attributes['titleOnHover']=='lpc-title-border') { |
| 201 |
$block_content .= ' .' . $blockuniqueclass . ' .lpc-title-border .blockspare-posts-block-post-grid-title .blockspare-posts-block-title-link span:hover{ |
| 202 |
box-shadow: inset 0 -2px 0 0 ' . $attributes['titleOnHoverColor'] . '; |
| 203 |
}'; |
| 204 |
} |
| 205 |
|
| 206 |
//Font Settings |
| 207 |
|
| 208 |
$block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-title a span{ |
| 209 |
font-size: ' . $attributes['postTitleFontSize'] . $attributes['titleFontSizeType'] . '; |
| 210 |
'.bscheckFontfamily($attributes['titleFontFamily']).'; |
| 211 |
'.bscheckFontfamilyWeight($attributes['titleFontWeight']).'; |
| 212 |
line-height: ' . $attributes['postTitleLineHeight'] . '; |
| 213 |
}'; |
| 214 |
|
| 215 |
$block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-content .blockspare-posts-block-post-grid-excerpt .blockspare-posts-block-post-grid-excerpt-content { |
| 216 |
font-size:' . $attributes['descriptionFontSize'] . $attributes['descriptionFontSizeType'] . '; |
| 217 |
'.bscheckFontfamily($attributes['descriptionFontFamily']).'; |
| 218 |
'.bscheckFontfamilyWeight($attributes['descriptionFontWeight']).'; |
| 219 |
}'; |
| 220 |
|
| 221 |
$block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-author a span { |
| 222 |
font-size:' . $attributes['postMetaFontSize'] . $attributes['postMetaFontSizeType'] . '; |
| 223 |
'.bscheckFontfamily($attributes['postMetaFontFamily']).'; |
| 224 |
'.bscheckFontfamilyWeight($attributes['postMetaFontWeight']).'; |
| 225 |
}'; |
| 226 |
|
| 227 |
$block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-date { |
| 228 |
font-size:' . $attributes['postMetaFontSize'] . $attributes['postMetaFontSizeType'] . '; |
| 229 |
'.bscheckFontfamily($attributes['postMetaFontFamily']).'; |
| 230 |
'.bscheckFontfamilyWeight($attributes['postMetaFontWeight']).'; |
| 231 |
}'; |
| 232 |
|
| 233 |
$block_content .= ' .' . $blockuniqueclass . ' .comment_count { |
| 234 |
font-size:' . $attributes['postMetaFontSize'] . $attributes['postMetaFontSizeType'] . '; |
| 235 |
'.bscheckFontfamily($attributes['postMetaFontFamily']).'; |
| 236 |
'.bscheckFontfamilyWeight($attributes['postMetaFontWeight']).'; |
| 237 |
}'; |
| 238 |
|
| 239 |
$block_content .= '@media (max-width: 1025px) { '; |
| 240 |
$block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-title a span{ |
| 241 |
font-size: ' . $attributes['titleFontSizeTablet'] . $attributes['titleFontSizeType'] . '; |
| 242 |
}'; |
| 243 |
$block_content .= ' .' . $blockuniqueclass .' .blockspare-posts-block-post-content .blockspare-posts-block-post-grid-excerpt .blockspare-posts-block-post-grid-excerpt-content { |
| 244 |
font-size:' . $attributes['descriptionFontSizeTablet'].$attributes['descriptionFontSizeType'].' |
| 245 |
}'; |
| 246 |
$block_content .= ' .' . $blockuniqueclass .' .blockspare-posts-block-post-grid-author a span { |
| 247 |
font-size:' . $attributes['postMetaFontSizeTablet'].$attributes['postMetaFontSizeType'].' |
| 248 |
}'; |
| 249 |
$block_content .= ' .' . $blockuniqueclass .' .blockspare-posts-block-post-grid-date { |
| 250 |
font-size:' . $attributes['postMetaFontSizeTablet'].$attributes['postMetaFontSizeType'].' |
| 251 |
}'; |
| 252 |
$block_content .= ' .' . $blockuniqueclass .' .comment_count { |
| 253 |
font-size:' . $attributes['postMetaFontSizeTablet'].$attributes['postMetaFontSizeType'].' |
| 254 |
}'; |
| 255 |
$block_content .= '}'; |
| 256 |
|
| 257 |
|
| 258 |
$block_content .= '@media (max-width: 767px) { '; |
| 259 |
$block_content .= ' .' . $blockuniqueclass . ' .blockspare-posts-block-post-grid-title a span{ |
| 260 |
font-size: ' . $attributes['titleFontSizeMobile'] . $attributes['titleFontSizeType'] . '; |
| 261 |
}'; |
| 262 |
$block_content .= ' .' . $blockuniqueclass .' .blockspare-posts-block-post-content .blockspare-posts-block-post-grid-excerpt .blockspare-posts-block-post-grid-excerpt-content { |
| 263 |
font-size:' . $attributes['descriptionFontSizeMobile'].$attributes['descriptionFontSizeType'].' |
| 264 |
}'; |
| 265 |
$block_content .= ' .' . $blockuniqueclass .' .blockspare-posts-block-post-grid-author a span { |
| 266 |
font-size:' . $attributes['postMetaFontSizeMobile'].$attributes['postMetaFontSizeType'].' |
| 267 |
}'; |
| 268 |
$block_content .= ' .' . $blockuniqueclass .' .blockspare-posts-block-post-grid-date { |
| 269 |
font-size:' . $attributes['postMetaFontSizeMobile'].$attributes['postMetaFontSizeType'].' |
| 270 |
}'; |
| 271 |
$block_content .= ' .' . $blockuniqueclass .' .comment_count { |
| 272 |
font-size:' . $attributes['postMetaFontSizeMobile'].$attributes['postMetaFontSizeType'].' |
| 273 |
}'; |
| 274 |
$block_content .= '}'; |
| 275 |
|
| 276 |
//Pagination |
| 277 |
if($attributes['enablePagination']){ |
| 278 |
if($attributes['loadMoreStyle'] == 'bs-loadmore-solid') { |
| 279 |
$block_content .=' .' . $blockuniqueclass . ' .bs_blockspare_loadmore a.blockspare-readmore .load-btn{ |
| 280 |
color:'.$attributes['loadMoreSolidTextColor'].'; |
| 281 |
background-color:'.$attributes['loadMoreTextBgColor'].'; |
| 282 |
}'; |
| 283 |
$block_content .=' .' . $blockuniqueclass . ' .bs_blockspare_loadmore a.blockspare-readmore .load-btn:hover{ |
| 284 |
color:'.$attributes['loadMoreSolidTextHoverColor'].'; |
| 285 |
background-color:'.$attributes['loadMoreTextBgHoverColor'].'; |
| 286 |
}'; |
| 287 |
} else { |
| 288 |
$block_content .=' .' . $blockuniqueclass . ' .bs_blockspare_loadmore a.blockspare-readmore .load-btn{ |
| 289 |
color:'.$attributes['loadMoreTextColor'].'; |
| 290 |
}'; |
| 291 |
$block_content .=' .' . $blockuniqueclass . ' .bs_blockspare_loadmore a.blockspare-readmore .load-btn:hover{ |
| 292 |
color:'.$attributes['loadMoreTextHoverColor'].'; |
| 293 |
}'; |
| 294 |
} |
| 295 |
|
| 296 |
$block_content .=' .' . $blockuniqueclass . ' .bs_blockspare_loadmore{ |
| 297 |
text-align:'.$attributes['loadMoreAlignment'].'; |
| 298 |
}'; |
| 299 |
$block_content .=' .' . $blockuniqueclass . ' .bs_blockspare_loadmore a.blockspare-readmore .ajax-loader-enabled{ |
| 300 |
border-top-color:'.$attributes['loadMoreColor'].'; |
| 301 |
}'; |
| 302 |
$block_content .= '}'; |
| 303 |
} |
| 304 |
|
| 305 |
|
| 306 |
$block_content .= '</style>'; |
| 307 |
return $block_content; |
| 308 |
} |
| 309 |
} |
| 310 |
|
| 311 |
|