| 1 |
<?php |
| 2 |
if (! defined('ABSPATH')) { |
| 3 |
exit; // Exit if accessed directly. |
| 4 |
} |
| 5 |
|
| 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 |
} |
| 19 |
|
| 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 |
); |
| 84 |
} |
| 85 |
} |
| 86 |
} |
| 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']; |
| 131 |
} |
| 132 |
|
| 133 |
|
| 134 |
if ($attributes['animation']) { |
| 135 |
$class .= ' blockspare-block-animation'; |
| 136 |
} |
| 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'; |
| 161 |
} |
| 162 |
|
| 163 |
$enableFeatureImage = true; |
| 164 |
if (isset($attributes['enableFeatureImage'])) { |
| 165 |
$enableFeatureImage = $attributes['enableFeatureImage']; |
| 166 |
} |
| 167 |
|
| 168 |
?> |
| 169 |
|
| 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 |
/* Setup the post ID */ |
| 178 |
$post_id = get_the_ID(); |
| 179 |
|
| 180 |
|
| 181 |
/* Setup the featured image ID */ |
| 182 |
$post_thumb_id = get_post_thumbnail_id($post_id); |
| 183 |
|
| 184 |
$has_img_class = ''; |
| 185 |
|
| 186 |
if (!$post_thumb_id) { |
| 187 |
$has_img_class = "post-has-no-image "; |
| 188 |
} |
| 189 |
|
| 190 |
|
| 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); ?> |
| 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 |
| 277 |
} |
| 278 |
?> |
| 279 |
</section> |
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
<?php } |
| 284 |
wp_reset_postdata(); |
| 285 |
} |
| 286 |
|
| 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; |
| 314 |
} |
| 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']; |
| 324 |
} |
| 325 |
} |
| 326 |
|
| 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'))); ?>" |
| 404 |
itemprop="url" rel="author"> |
| 405 |
<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'))); ?> |
| 408 |
</span> |
| 409 |
</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 --> |
| 417 |
|
| 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 --> |
| 424 |
|
| 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 --> |
| 434 |
|
| 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> |
| 466 |
<?php } |
| 467 |
|
| 468 |
|
| 469 |
function bscheckFontfamily($fontFamily) |
| 470 |
{ |
| 471 |
|
| 472 |
$fonts = ''; |
| 473 |
if ($fontFamily != 'Default' && $fontFamily != "undefined") { |
| 474 |
$fonts = 'font-family:' . $fontFamily; |
| 475 |
} |
| 476 |
return $fonts; |
| 477 |
} |
| 478 |
|
| 479 |
|
| 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() |
| 510 |
); |
| 511 |
} |
| 512 |
|
| 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 |
} |
| 523 |
|