| 1 |
<?php |
| 2 |
if ( $terms_query_args == false ) { |
| 3 |
return; |
| 4 |
} |
| 5 |
|
| 6 |
$terms = get_terms( apply_filters( 'betterdocs_base_terms_args', $terms_query_args ) ); |
| 7 |
/** |
| 8 |
* Base Layout Before Wrapper |
| 9 |
*/ |
| 10 |
do_action_ref_array( 'betterdocs_base_layout_wrapper_before', [ & $terms] ); |
| 11 |
?> |
| 12 |
|
| 13 |
<div |
| 14 |
<?php echo $wrapper_attr; ?>> |
| 15 |
<?php |
| 16 |
/** |
| 17 |
* Base Layout Before Inner Wrapper |
| 18 |
*/ |
| 19 |
do_action_ref_array( 'betterdocs_base_layout_inner_wrapper_before', [ & $terms] ); |
| 20 |
?> |
| 21 |
<div |
| 22 |
<?php echo $inner_wrapper_attr; ?>> |
| 23 |
<?php |
| 24 |
$_defined_vars = get_defined_vars(); |
| 25 |
$_params = isset( $_defined_vars['params'] ) ? $_defined_vars['params'] : []; |
| 26 |
|
| 27 |
$nested_subcategory = isset( $nested_subcategory ) ? $nested_subcategory : false; |
| 28 |
|
| 29 |
$_current_queried_object_id = null; |
| 30 |
$_current_queried_object = get_queried_object(); |
| 31 |
|
| 32 |
if ( $_current_queried_object instanceof \WP_Post ) { |
| 33 |
$_current_terms = get_the_terms( $_current_queried_object->ID, 'doc_category' ); |
| 34 |
$_current_queried_object_id = isset( $_current_terms[0]->term_id ) ? $_current_terms[0]->term_id : null; |
| 35 |
} elseif ( $_current_queried_object instanceof \WP_Term ) { |
| 36 |
$_current_queried_object_id = $_current_queried_object->term_id; |
| 37 |
} |
| 38 |
|
| 39 |
$ancestors = []; |
| 40 |
|
| 41 |
if ( is_single() && ! empty( $_current_queried_object_id ) ) { |
| 42 |
$_category_ids = wp_get_post_terms( get_the_ID(), 'doc_category', ["fields" => "ids"] ); |
| 43 |
$ancestors = get_ancestors( $_category_ids[0], 'doc_category' ); |
| 44 |
} |
| 45 |
|
| 46 |
if ( ! is_wp_error( $terms ) ) { |
| 47 |
do_action_ref_array( 'betterdocs_layout_base_loop_start', [ & $terms, &$_defined_vars] ); |
| 48 |
|
| 49 |
$_docs_query_args = [ |
| 50 |
'posts_per_page' => isset( $_params['posts_per_page'] ) ? $_params['posts_per_page'] : 0, |
| 51 |
'multiple_kb' => isset( $_params['multiple_knowledge_base'] ) ? $_params['multiple_knowledge_base'] : false, |
| 52 |
'kb_slug' => isset( $_params['kb_slug'] ) ? $_params['kb_slug'] : '' |
| 53 |
]; |
| 54 |
|
| 55 |
$docs_query_args = ! isset( $docs_query_args ) ? $_docs_query_args : wp_parse_args( $docs_query_args, $_docs_query_args ); |
| 56 |
|
| 57 |
$terms_count = count( $terms ); |
| 58 |
$terms_number = 1; |
| 59 |
foreach ( $terms as $term ) { |
| 60 |
$_counts = betterdocs()->query->get_docs_count( $term, $nested_subcategory, [ |
| 61 |
'multiple_knowledge_base' => isset( $_params['multiple_knowledge_base'] ) ? $_params['multiple_knowledge_base'] : false, |
| 62 |
'kb_slug' => isset( $_params['kb_slug'] ) ? $_params['kb_slug'] : '' |
| 63 |
] ); |
| 64 |
|
| 65 |
if ( $_counts <= 0 ) { |
| 66 |
continue; |
| 67 |
} |
| 68 |
|
| 69 |
if ( $widget_type == 'category-box' || ( $widget_type == 'category-grid' && $layout == 'layout-2' ) ) { |
| 70 |
$_counts = [ |
| 71 |
'counts' => $_counts, |
| 72 |
'prefix' => ! empty( $count_prefix ) ? $count_prefix : '', |
| 73 |
'suffix' => ! empty( $count_suffix ) ? $count_suffix : '', |
| 74 |
'suffix_singular' => ! empty( $count_suffix_singular ) ? $count_suffix_singular : '' |
| 75 |
]; |
| 76 |
} |
| 77 |
|
| 78 |
// Count Sub Terms |
| 79 |
$sub_terms_count = 0; |
| 80 |
if ( isset( $_params['taxonomy'] ) && $_params['taxonomy'] == 'doc_category' ) { |
| 81 |
$sub_terms_count = count( betterdocs()->query->get_all_child_term_ids( $_params['taxonomy'], $term->term_id ) ); |
| 82 |
} else if ( isset( $_params['taxonomy'] ) && $_params['taxonomy'] == 'knowledge_base' ) { |
| 83 |
$count_doc_categories = betterdocs()->query->count_doc_categories_for_knowledge_base( $term->slug ); |
| 84 |
$sub_terms_count = $count_doc_categories; |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
$permalink = apply_filters( |
| 89 |
'betterdocs_term_permalink', |
| 90 |
get_term_link( $term->term_id, $term->taxonomy ), $term, 'doc_category', $_params |
| 91 |
); |
| 92 |
|
| 93 |
$docs_query_args['term_id'] = $term->term_id; |
| 94 |
$docs_query_args['term_slug'] = $term->slug; |
| 95 |
$docs_query_args['nested_subcategory'] = $nested_subcategory; |
| 96 |
|
| 97 |
$_params = wp_parse_args( [ |
| 98 |
'permalink' => $permalink, |
| 99 |
'wrapper_class' => [$layout], |
| 100 |
'term' => $term, |
| 101 |
'counts' => $_counts, |
| 102 |
'terms_count' => $terms_count, |
| 103 |
'terms_number' => $terms_number, |
| 104 |
'sub_terms_count' => $sub_terms_count, |
| 105 |
'queried_object' => $_current_queried_object, |
| 106 |
'current_queried_object_id' => $_current_queried_object_id, |
| 107 |
'ancestors' => $ancestors, |
| 108 |
'query_args' => betterdocs()->query->docs_query_args( $docs_query_args ) |
| 109 |
], $_params ); |
| 110 |
|
| 111 |
$template_params = apply_filters( 'betterdocs_template_params', $_params, $layout, $term, $widget_type ); |
| 112 |
$layout_filename = apply_filters( 'betterdocs_layout_filename', $layout, $layout, $widget_type ); |
| 113 |
|
| 114 |
betterdocs()->views->get( 'layouts/' . $widget_type . '/' . $layout_filename, $template_params ); |
| 115 |
$terms_number++; |
| 116 |
$terms_count--; |
| 117 |
} |
| 118 |
|
| 119 |
do_action_ref_array( 'betterdocs_layout_base_loop_end', [ & $terms, &$_defined_vars] ); |
| 120 |
} else { |
| 121 |
betterdocs()->views->get( 'layout-parts/no-content' ); |
| 122 |
} |
| 123 |
|
| 124 |
wp_reset_postdata(); |
| 125 |
?> |
| 126 |
</div> |
| 127 |
<?php |
| 128 |
/** |
| 129 |
* Base Layout After Inner Wrapper |
| 130 |
*/ |
| 131 |
do_action_ref_array( 'betterdocs_base_layout_inner_wrapper_after', [ & $terms] ); |
| 132 |
?> |
| 133 |
<div class="clearfix"></div> |
| 134 |
<?php if ( isset( $is_edit_mode ) && $is_edit_mode && $widget_type == 'category-grid' ): ?> |
| 135 |
<script> |
| 136 |
/** |
| 137 |
* TODO: Not working in Elementor Editor on first Load. |
| 138 |
*/ |
| 139 |
jQuery(document).ready(function($) { |
| 140 |
$('.betterdocs-category-grid').each(function() { |
| 141 |
let $grid = $(this), |
| 142 |
$layout_mode = $grid.data('layout-mode'), |
| 143 |
$column = $grid.data('column'), |
| 144 |
$column_space = $grid.data('column_space'); |
| 145 |
if ($layout_mode === 'masonry') { |
| 146 |
let masonryItem = $(".betterdocs-single-category-wrapper", $grid); |
| 147 |
let total_margin = ($column - 1) * $column_space; |
| 148 |
masonryItem.css("width", "calc((100% - " + total_margin + "px) / " + parseInt($column) + ")"); |
| 149 |
$grid.masonry({ |
| 150 |
itemSelector: ".betterdocs-single-category-wrapper", |
| 151 |
percentPosition: true, |
| 152 |
gutter: $column_space |
| 153 |
}); |
| 154 |
} |
| 155 |
}); |
| 156 |
}); |
| 157 |
</script> |
| 158 |
<?php endif;?> |
| 159 |
</div> |
| 160 |
<?php |
| 161 |
/** |
| 162 |
* Base Layout After Wrapper |
| 163 |
*/ |
| 164 |
do_action_ref_array( 'betterdocs_base_layout_wrapper_after', [ & $terms] ); |
| 165 |
?> |
| 166 |
|