get( 'enable_breadcrumbs', true ) ) : ?>
/ knowledge_base ) ) : ?> get( 'docs_page_title', 'Knowledge Base' ) ); ?> / name ); ?> get( 'docs_page_title', 'Knowledge Base' ) ); ?>
get( 'enable_live_search', true ) ) : ?> get( 'enable_multiple_kb', false ); $post_type_obj = \Acumenon\Core\PostType::get_instance(); // Helper function to render a category grid given an array of category terms $render_category_grid = function( $cat_terms, $uncategorized_ids = [], $current_kb_id = null ) use ( $post_type_obj ) { if ( ( empty( $cat_terms ) || is_wp_error( $cat_terms ) ) && empty( $uncategorized_ids ) ) { echo '

' . esc_html__( 'No categories found.', 'acumenon' ) . '

'; return; } echo '
'; if ( ! empty( $cat_terms ) && ! is_wp_error( $cat_terms ) ) { foreach ( $cat_terms as $term ) { // Filter: Hide restricted category if ( ! \Acumenon\Core\AccessControl::can_user_access_term( $term->term_id, $post_type_obj->category ) ) { continue; } // Fetch up to 4 posts for this category, filtered by KB if applicable $cat_posts_args = [ 'post_type' => $post_type_obj->post_type, 'posts_per_page' => 4, 'tax_query' => [ [ 'taxonomy' => $post_type_obj->category, 'field' => 'term_id', 'terms' => $term->term_id ] ] ]; if ( $current_kb_id ) { $cat_posts_args['tax_query'][] = [ 'taxonomy' => $post_type_obj->knowledge_base, 'field' => 'term_id', 'terms' => $current_kb_id ]; $cat_posts_args['tax_query']['relation'] = 'AND'; } $cat_posts = get_posts( $cat_posts_args ); ?>

name ); ?>

    ID ) ) { continue; } if ( $count >= 3 ) break; // Only show 3 ?>
3 ) : ?>

    = 3; if ( $is_hidden ) $has_hidden = true; ?>
'; }; $is_root_display = is_post_type_archive( $post_type_obj->post_type ) || ( is_page() && get_post_meta( get_the_ID(), '_wp_page_template', true ) === 'acumenon-kb-template.php' ); if ( $is_multiple_kb_enabled ) { $kb_terms = get_terms( [ 'taxonomy' => $post_type_obj->knowledge_base, 'hide_empty' => false, ] ); if ( ! empty( $kb_terms ) && ! is_wp_error( $kb_terms ) ) { // Determine active KB $current_kb = null; if ( is_tax( $post_type_obj->knowledge_base ) ) { $current_kb = get_queried_object(); } elseif ( $is_root_display ) { $current_kb = $kb_terms[0]; // Default to first } // Render Tabs echo '
'; foreach ( $kb_terms as $kb ) { // Filter: Hide restricted Knowledge Base if ( ! \Acumenon\Core\AccessControl::can_user_access_term( $kb->term_id, $post_type_obj->knowledge_base ) ) { continue; } $active_class = ( $current_kb && $current_kb->term_id === $kb->term_id ) ? ' active' : ''; echo sprintf( '%s', esc_url( get_term_link( $kb ) ), esc_attr( $active_class ), esc_html( $kb->name ) ); } echo '
'; // Render Content for Current KB if ( $current_kb ) { $kb_posts = get_posts( [ 'post_type' => $post_type_obj->post_type, 'posts_per_page' => -1, 'fields' => 'ids', 'tax_query' => [ [ 'taxonomy' => $post_type_obj->knowledge_base, 'field' => 'term_id', 'terms' => $current_kb->term_id, ] ] ] ); if ( ! empty( $kb_posts ) ) { $cat_terms = wp_get_object_terms( $kb_posts, $post_type_obj->category ); // Find Uncategorized Posts in this KB $uncategorized_ids = get_posts( [ 'post_type' => $post_type_obj->post_type, 'posts_per_page' => -1, 'fields' => 'ids', 'tax_query' => [ 'relation' => 'AND', [ 'taxonomy' => $post_type_obj->knowledge_base, 'field' => 'term_id', 'terms' => $current_kb->term_id, ], [ 'taxonomy' => $post_type_obj->category, 'field' => 'id', 'operator' => 'NOT EXISTS' ] ] ] ); $render_category_grid( $cat_terms, $uncategorized_ids, $current_kb->term_id ); } else { echo '

' . esc_html__( 'No categories found in this Knowledge Base.', 'acumenon' ) . '

'; } } } } else { // Standard (Multiple KBs disabled): Render single grid of all categories $cat_terms = get_terms( [ 'taxonomy' => $post_type_obj->category, 'hide_empty' => false, ] ); // Find Uncategorized Posts $uncategorized_ids = get_posts( [ 'post_type' => $post_type_obj->post_type, 'posts_per_page' => -1, 'fields' => 'ids', 'tax_query' => [ [ 'taxonomy' => $post_type_obj->category, 'field' => 'id', 'operator' => 'NOT EXISTS' ] ] ] ); $render_category_grid( $cat_terms, $uncategorized_ids ); } ?>