category_tree(); $breadcrumbs = Render::all_breadcrumbs($categories); // get ALL posts of category $posts = $wiki->latest_published_posts($category_id, 0); // special case: // ----------------------------------------------------------------------------- // ONE post + NO subcaegories ..then redirect to the only post if (($breadcrumbs[ $category_id ]['childs'] == []) && (count($posts) == 1)) { header('Location: /wiki/post?id='. $posts[0]['id'], true, 302); die(); } // find parent_ids of current category (to open the menu tree) $category_path = []; foreach($breadcrumbs[$category_id]['parents'] as $parent) { $category_path[] = intval($parent['id']); } $category_path[] = intval($category_id); // format $posts array // --- $posts_formated = []; foreach($posts as $post) { $date = DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $post['creation_date']); $posts_formated[] = [ 'id' => $post['id'], 'title' => $post['title'], 'intro' => $post['intro'] ?? false, 'date' => Render::date_box($post['creation_date']) ]; } // then render the page ... // ----------------------------------------------------------------------------- ?>