]*\sid\s*=\s*([\'\"])icindekiler\1[^>]*>.*?~is'; if (preg_match_all($pattern, $content, $matches, PREG_OFFSET_CAPTURE) !== 1) return $content; $toc = $matches[0][0][0]; $position = $matches[0][0][1]; // Only the existing simple native TOC is handled; malformed/nested markup is untouched. if (preg_match_all('~]*>.*?~is', $intro, $paragraph, PREG_OFFSET_CAPTURE)) return $content; $after_intro = $paragraph[0][1] + strlen($paragraph[0][0]); $opening_end = strpos($toc, '>') + 1; $opening = preg_replace('~\s+open(?:\s*=\s*(?:"[^"]*"|\'[^\']*\'|[^\s>]+))?(?=\s|>)~i', '', substr($toc, 0, $opening_end), 1); $toc = $opening.substr($toc, $opening_end); if (trim(substr($intro, $after_intro)) === '' && $toc === $matches[0][0][0]) return $content; return substr($content, 0, $after_intro)."\n".$toc.substr($content, $after_intro, $position - $after_intro) .substr($content, $position + strlen($matches[0][0][0])); } add_filter('the_content', 'baa_early_article_toc', 18); /** Explicit editorial classification; old posts retain their neutral label. */ function baa_article_kind($id) { $labels = ['short' => 'Kısa çözüm', 'guide' => 'Ayrıntılı rehber', 'experience' => 'Deneyim notu']; $kind = get_post_meta($id, '_baa_article_kind', true); return $labels[$kind] ?? 'Yazı'; } function baa_project_guide($slug) { $post = get_page_by_path($slug, OBJECT, 'post'); return $post && $post->post_status === 'publish' ? $post : null; } function baa_projects_manifest() { return baa_read_data('projects.json'); } function baa_series_navigation($id) { $manifest = baa_projects_manifest(); $projects = $manifest['projects'] ?? []; $posts = array_map(function($project) { return baa_project_guide($project['slug']); }, $projects); $position = null; foreach ($posts as $i => $post) if ($post && (int)$post->ID === (int)$id) $position = $i; if ($position === null) return; // Do not skip an unpublished adjacent chapter or invent a destination. $previous = $posts[$position - 1] ?? null; $next = $posts[$position + 1] ?? null; ?>