get_chapter_nav($current_id); $prev_page = $nav['prev']; $next_page = $nav['next']; } else { $parent_id = wp_get_post_parent_id($current_id); $siblings = get_pages([ 'parent' => $parent_id ?: 0, 'sort_column' => 'menu_order, post_title', 'sort_order' => 'ASC', 'post_status' => 'publish', ]); $current_index = -1; foreach ($siblings as $i => $sibling) { if ((int) $sibling->ID === $current_id) { $current_index = $i; break; } } $prev_page = $current_index > 0 ? $siblings[$current_index - 1] : null; $next_page = ($current_index >= 0 && $current_index < count($siblings) - 1) ? $siblings[$current_index + 1] : null; } if (!$prev_page && !$next_page) return; ?>