| @@ -1,39 +1,64 @@ | ||
| 1 | 1 | <?php |
| 2 | - use WPDeveloper\BetterDocs\Utils\Helper; | |
| 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; | |
| 3 | 8 | |
| 4 | - $attributes = [ | |
| 5 | - 'data-id' => isset( $term->term_id ) ? $term->term_id : 0, | |
| 6 | - 'class' => ['betterdocs-single-category-wrapper category-grid'] | |
| 7 | - ]; | |
| 9 | + $attributes = [ | |
| 10 | + 'data-id' => isset( $term->term_id ) ? $term->term_id : 0, | |
| 11 | + 'class' => [ 'betterdocs-single-category-wrapper category-grid' ] | |
| 12 | + ]; | |
| 8 | 13 | |
| 9 | - if ( is_single() && ( $term->term_id === $current_queried_object_id || ( (bool) $nested_subcategory && in_array( $term->term_id, $ancestors ) ) ) ) { | |
| 10 | - $attributes['class'][] = 'active'; | |
| 11 | - } elseif ( Helper::get_tax() == 'doc_category' && $term->term_id === $current_queried_object_id ) { | |
| 12 | - $attributes['class'][] = 'active'; | |
| 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 | + } | |
| 14 | 23 | |
| 15 | - if ( isset( $wrapper_class ) && is_array( $wrapper_class ) && ! empty( $wrapper_class ) ) { | |
| 16 | - $attributes['class'] = array_merge( $attributes['class'], $wrapper_class ); | |
| 17 | - } | |
| 24 | + if ( isset( $wrapper_class ) && is_array( $wrapper_class ) && ! empty( $wrapper_class ) ) { | |
| 25 | + $attributes['class'] = array_merge( $attributes['class'], $wrapper_class ); | |
| 26 | + } | |
| 18 | 27 | |
| 19 | - $attributes = betterdocs()->template_helper->get_html_attributes( $attributes ); | |
| 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; | |
| 20 | 33 | ?> |
| 21 | 34 | |
| 22 | 35 | <article |
| 23 | - <?php echo $attributes; ?>> | |
| 36 | + <?php echo $attributes; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>> | |
| 24 | 37 | <div class="betterdocs-single-category-inner"> |
| 25 | 38 | <?php |
| 26 | - if ( $show_header ) { | |
| 27 | - $view_object->get( 'layout-parts/header' ); | |
| 28 | - } | |
| 39 | + if ( $show_header ) { | |
| 40 | + $view_object->get( 'layout-parts/header' ); | |
| 41 | + } | |
| 29 | 42 | |
| 30 | - if ( $show_list ) { | |
| 31 | - echo '<div class="betterdocs-body">'; | |
| 32 | - $view_object->get( 'template-parts/category-list' ); | |
| 33 | - echo '</div>'; | |
| 34 | - } | |
| 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 | + } | |
| 35 | 58 | |
| 36 | - $view_object->get( 'layout-parts/footer' ); | |
| 37 | - ?> | |
| 59 | + if( $posts_per_page < $current_term_posts_count ) { | |
| 60 | + $view_object->get( 'layout-parts/footer' ); | |
| 61 | + } | |
| 62 | + ?> | |
| 38 | 63 | </div> |
| 39 | 64 | </article> |