PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.9.3
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.9.3
4.9.3 4.9.2 4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 3.4.2 3.5.0 All 201 releases
betterdocs / views / templates / parts / navigation.php

navigation.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 4.9.3, at views/templates/parts/navigation.php

129 lines 5.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- view template receives variables via extract(); prefixing is impractical.
3
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8 if ( ! betterdocs()->settings->get( 'enable_navigation' ) ) {
9 return;
10 }
11
12 // Get current post
13 $current_post = get_post();
14 if ( ! $current_post || 'docs' !== $current_post->post_type ) {
15 return;
16 }
17
18 // Get the doc_category terms for current post
19 $terms = get_the_terms( $current_post->ID, 'doc_category' );
20 if ( empty( $terms ) || is_wp_error( $terms ) ) {
21 return;
22 }
23
24 // Use the first term for navigation
25 $current_term = $terms[ 0 ];
26
27 // Build query args same as category-list.php
28 $query_args = betterdocs()->query->docs_query_args(
29 array(
30 'post_type' => 'docs',
31 'posts_per_page' => -1,
32 'term_id' => $current_term->term_id,
33 'term_slug' => $current_term->slug,
34 'orderby' => betterdocs()->settings->get( 'alphabetically_order_post', 'betterdocs_order' ),
35 'order' => betterdocs()->settings->get( 'docs_order', 'ASC' )
36 )
37 );
38
39 // Get posts using the same method as category-list.php
40 $posts = betterdocs()->query->get_posts( $query_args, true );
41
42 if ( ! $posts->have_posts() ) {
43 wp_reset_postdata();
44 return;
45 }
46
47 // Build array of post IDs in order
48 $post_ids = array();
49 while ( $posts->have_posts() ) {
50 $posts->the_post();
51 $post_ids[ ] = get_the_ID();
52 }
53 wp_reset_postdata();
54
55 // Find current post position
56 $current_index = array_search( $current_post->ID, $post_ids, true );
57
58 if ( false === $current_index ) {
59 return;
60 }
61
62 // Get previous and next post IDs with circular navigation
63 $total_posts = count( $post_ids );
64 $last_index = $total_posts - 1;
65
66 // If current is first item, prev wraps to last item
67 $prev_post_id = ( 0 === $current_index ) ? $post_ids[ $last_index ] : $post_ids[ $current_index - 1 ];
68
69 // If current is last item, next wraps to first item
70 $next_post_id = ( $last_index === $current_index ) ? $post_ids[ 0 ] : $post_ids[ $current_index + 1 ];
71
72 // SVG icons
73 $prev_icon = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="42px" viewBox="0 0 50 50" version="1.1"><g id="surface1"><path style=" " d="M 11.957031 13.988281 C 11.699219 14.003906 11.457031 14.117188 11.28125 14.308594 L 1.015625 25 L 11.28125 35.691406 C 11.527344 35.953125 11.894531 36.0625 12.242188 35.976563 C 12.589844 35.890625 12.867188 35.625 12.964844 35.28125 C 13.066406 34.933594 12.972656 34.5625 12.71875 34.308594 L 4.746094 26 L 48 26 C 48.359375 26.003906 48.695313 25.816406 48.878906 25.503906 C 49.058594 25.191406 49.058594 24.808594 48.878906 24.496094 C 48.695313 24.183594 48.359375 23.996094 48 24 L 4.746094 24 L 12.71875 15.691406 C 13.011719 15.398438 13.09375 14.957031 12.921875 14.582031 C 12.753906 14.203125 12.371094 13.96875 11.957031 13.988281 Z "></path></g></svg>';
74 $next_icon = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="42px" viewBox="0 0 50 50" version="1.1"><g id="surface1"><path style=" " d="M 38.035156 13.988281 C 37.628906 13.980469 37.257813 14.222656 37.09375 14.59375 C 36.933594 14.96875 37.015625 15.402344 37.300781 15.691406 L 45.277344 24 L 2.023438 24 C 1.664063 23.996094 1.328125 24.183594 1.148438 24.496094 C 0.964844 24.808594 0.964844 25.191406 1.148438 25.503906 C 1.328125 25.816406 1.664063 26.003906 2.023438 26 L 45.277344 26 L 37.300781 34.308594 C 36.917969 34.707031 36.933594 35.339844 37.332031 35.722656 C 37.730469 36.105469 38.363281 36.09375 38.746094 35.691406 L 49.011719 25 L 38.746094 14.308594 C 38.5625 14.109375 38.304688 13.996094 38.035156 13.988281 Z "></path></g></svg>';
75
76 // Build navigation HTML
77 $nav = '';
78
79 if ( $prev_post_id ) {
80 $prev_post = get_post( $prev_post_id );
81 $prev_title = get_the_title( $prev_post_id );
82 $prev_link = get_permalink( $prev_post_id );
83 $nav .= sprintf(
84 '<a href="%s" rel="prev">%s %s</a>',
85 esc_url( $prev_link ),
86 $prev_icon,
87 esc_html( $prev_title )
88 );
89 }
90
91 if ( $next_post_id ) {
92 $next_post = get_post( $next_post_id );
93 $next_title = get_the_title( $next_post_id );
94 $next_link = get_permalink( $next_post_id );
95 $nav .= sprintf(
96 '<a href="%s" rel="next">%s %s</a>',
97 esc_url( $next_link ),
98 esc_html( $next_title ),
99 $next_icon
100 );
101 }
102
103 $wrapper_attr_array = array();
104
105 if ( isset( $widget_type ) && 'betterdocs-navigation' !== $widget_type ) {
106 $wrapper_attr_array = array( 'class' => array() );
107 }
108
109 if ( ! empty( $wrapper_attr_array ) ) {
110 $wrapper_attr_array[ 'class' ][ ] = 'docs-navigation';
111 if ( isset( $wraper_class ) ) {
112 $wrapper_attr_array[ 'class' ][ ] = $wraper_class;
113 }
114 if ( isset( $widget_type ) && 'blocks' === $widget_type ) {
115 $wrapper_attr_array[ 'class' ][ ] = $blockId;
116 }
117 }
118 $wrapper_attr = betterdocs()->template_helper->get_html_attributes( $wrapper_attr_array );
119
120 if ( empty( $nav ) ) {
121 return;
122 }
123 ?>
124
125 <div
126 <?php echo $wrapper_attr; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
127 <?php echo apply_filters( 'betterdocs_single_post_nav', $nav ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
128 </div>
129