| 1 |
<?php |
| 2 |
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- view template receives variables via extract(); prefixing is impractical. |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
use WPDeveloper\BetterDocs\Utils\Helper; |
| 8 |
|
| 9 |
$attributes = [ |
| 10 |
'data-id' => isset( $term->term_id ) ? $term->term_id : 0, |
| 11 |
'class' => [ 'betterdocs-single-category-wrapper category-grid' ] |
| 12 |
]; |
| 13 |
|
| 14 |
$is_active = false; |
| 15 |
if ( is_single() && ( $term->term_id === $current_queried_object_id || ( (bool) $nested_subcategory && in_array( $term->term_id, $ancestors ) ) ) ) { |
| 16 |
$is_active = true; |
| 17 |
} elseif ( Helper::get_tax() == 'doc_category' && $term->term_id === $current_queried_object_id || ( (bool) $nested_subcategory && Helper::get_tax() == 'doc_category' && Helper::get_the_top_most_parent( $current_queried_object_id ) == $term->term_id ) ) { |
| 18 |
$is_active = true; |
| 19 |
} |
| 20 |
if ( $is_active ) { |
| 21 |
$attributes['class'][] = 'active'; |
| 22 |
} |
| 23 |
|
| 24 |
if ( isset( $wrapper_class ) && is_array( $wrapper_class ) && ! empty( $wrapper_class ) ) { |
| 25 |
$attributes['class'] = array_merge( $attributes['class'], $wrapper_class ); |
| 26 |
} |
| 27 |
|
| 28 |
$attributes = betterdocs()->template_helper->get_html_attributes( $attributes ); |
| 29 |
$posts_per_page = isset( $docs_query_args['posts_per_page'] ) ? $docs_query_args['posts_per_page'] : ( isset( $post_per_tab ) ? $post_per_tab : ( isset($post_per_page) ? $post_per_page : 0 ) ); // for category grid, mkb, tab |
| 30 |
$current_term_posts_count = isset( $counts ) && ! is_array( $counts ) ? $counts : ( isset( $counts ) && is_array( $counts ) ? $counts['counts'] : 0 ); |
| 31 |
|
| 32 |
$is_lazy_body = ! empty( $lazy_load ) && ! $is_active; |
| 33 |
?> |
| 34 |
|
| 35 |
<article |
| 36 |
<?php echo $attributes; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>> |
| 37 |
<div class="betterdocs-single-category-inner"> |
| 38 |
<?php |
| 39 |
if ( $show_header ) { |
| 40 |
$view_object->get( 'layout-parts/header' ); |
| 41 |
} |
| 42 |
|
| 43 |
if ( $show_list ) { |
| 44 |
if ( $is_lazy_body ) { |
| 45 |
// Empty placeholder. JS injects the skeleton on click and swaps |
| 46 |
// in real docs once the AJAX completes (with a 1s minimum |
| 47 |
// display so the loading state is perceptible). |
| 48 |
printf( |
| 49 |
'<div class="betterdocs-body" data-bd-lazy="1" data-bd-term-id="%d" style="display:none;"></div>', |
| 50 |
(int) $term->term_id |
| 51 |
); |
| 52 |
} else { |
| 53 |
echo '<div class="betterdocs-body">'; |
| 54 |
$view_object->get( 'template-parts/category-list' ); |
| 55 |
echo '</div>'; |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
if( $posts_per_page < $current_term_posts_count ) { |
| 60 |
$view_object->get( 'layout-parts/footer' ); |
| 61 |
} |
| 62 |
?> |
| 63 |
</div> |
| 64 |
</article> |
| 65 |
|