settings->get( 'enable_navigation' ) ) { return; } // Get current post $current_post = get_post(); if ( ! $current_post || 'docs' !== $current_post->post_type ) { return; } // Get the doc_category terms for current post $terms = get_the_terms( $current_post->ID, 'doc_category' ); if ( empty( $terms ) || is_wp_error( $terms ) ) { return; } // Use the first term for navigation $current_term = $terms[ 0 ]; // Build query args same as category-list.php $query_args = betterdocs()->query->docs_query_args( array( 'post_type' => 'docs', 'posts_per_page' => -1, 'term_id' => $current_term->term_id, 'term_slug' => $current_term->slug, 'orderby' => betterdocs()->settings->get( 'alphabetically_order_post', 'betterdocs_order' ), 'order' => betterdocs()->settings->get( 'docs_order', 'ASC' ) ) ); // Get posts using the same method as category-list.php $posts = betterdocs()->query->get_posts( $query_args, true ); if ( ! $posts->have_posts() ) { wp_reset_postdata(); return; } // Build array of post IDs in order $post_ids = array(); while ( $posts->have_posts() ) { $posts->the_post(); $post_ids[ ] = get_the_ID(); } wp_reset_postdata(); // Find current post position $current_index = array_search( $current_post->ID, $post_ids, true ); if ( false === $current_index ) { return; } // Get previous and next post IDs with circular navigation $total_posts = count( $post_ids ); $last_index = $total_posts - 1; // If current is first item, prev wraps to last item $prev_post_id = ( 0 === $current_index ) ? $post_ids[ $last_index ] : $post_ids[ $current_index - 1 ]; // If current is last item, next wraps to first item $next_post_id = ( $last_index === $current_index ) ? $post_ids[ 0 ] : $post_ids[ $current_index + 1 ]; // SVG icons $prev_icon = ''; $next_icon = ''; // Build navigation HTML $nav = ''; if ( $prev_post_id ) { $prev_post = get_post( $prev_post_id ); $prev_title = get_the_title( $prev_post_id ); $prev_link = get_permalink( $prev_post_id ); $nav .= sprintf( '%s %s', esc_url( $prev_link ), $prev_icon, esc_html( $prev_title ) ); } if ( $next_post_id ) { $next_post = get_post( $next_post_id ); $next_title = get_the_title( $next_post_id ); $next_link = get_permalink( $next_post_id ); $nav .= sprintf( '%s %s', esc_url( $next_link ), esc_html( $next_title ), $next_icon ); } $wrapper_attr_array = array(); if ( isset( $widget_type ) && 'betterdocs-navigation' !== $widget_type ) { $wrapper_attr_array = array( 'class' => array() ); } if ( ! empty( $wrapper_attr_array ) ) { $wrapper_attr_array[ 'class' ][ ] = 'docs-navigation'; if ( isset( $wraper_class ) ) { $wrapper_attr_array[ 'class' ][ ] = $wraper_class; } if ( isset( $widget_type ) && 'blocks' === $widget_type ) { $wrapper_attr_array[ 'class' ][ ] = $blockId; } } $wrapper_attr = betterdocs()->template_helper->get_html_attributes( $wrapper_attr_array ); if ( empty( $nav ) ) { return; } ?>