This is a complete architectural overview of your informational website project. Since you are building this with PHP, this structure is modular: the data is stored in JSON, and the design is handled by reusable Templates.
File Structure Overview
To make this work, place all these files in the same root folder on your server:
* index.php (The Category Setup Form)
* dashboard.php (The Management Control Center)
* edit_article.php (The Content Editor)
* category.php (The SEO-Friendly Template)
* header.php (The Global Navigation & Search)
* functions.php (Helper functions for SEO)
* .htaccess (URL Rewriting rules)
* categories.json (Stores your 20 categories)
* content.json (Stores article text and meta tags)
1. functions.php
This handles the logic for creating SEO-friendly slugs.
<?php
function createSlug($string) {
// Converts “Digital Marketing 101” to “digital-marketing-101”
$slug = strtolower(trim(preg_replace(‘/[^A-Za-z0-9-]+/’, ‘-‘, $string)));
return $slug;
}
?>
2. .htaccess
Crucial: This file must be named exactly .htaccess to enable pretty URLs.
RewriteEngine On
# Redirect /category/slug-name to category.php?name=slug-name
RewriteRule ^category/([^/]+)/?$ category.php?name=$1 [L,QSA]
# Redirect /sitemap.xml to our dynamic PHP sitemap
RewriteRule ^sitemap\.xml$ sitemap.php [L]
3. header.php
The global header with dynamic navigation and search functionality.
<?php
include_once ‘functions.php’;
$cat_file = ‘categories.json’;
$nav_categories = file_exists($cat_file) ? json_decode(file_get_contents($cat_file), true) : [];
?>
<style>
body { font-family: sans-serif; margin: 0; padding-top: 60px; }
.site-header { background: #2c3e50; color: white; padding: 10px; position: fixed; top:0; width: 100%; z-index:100; }
.nav-container { max-width: 1100px; margin: auto; display: flex; justify-content: space-between; align-items: center; }
.nav-menu { display: flex; list-style: none; gap: 15px; }
.nav-menu a { color: white; text-decoration: none; font-size: 14px; }
.search-box input { padding: 5px; border-radius: 15px; border: none; }
</style>
<header class=”site-header”>
<div class=”nav-container”>
<div class=”logo”><strong>INFO PORTAL</strong></div>
<nav>
<ul class=”nav-menu”>
<li><a href=”index.php”>Setup</a></li>
<li><a href=”dashboard.php”>Dashboard</a></li>
<?php foreach(array_slice($nav_categories, 0, 3) as $c): ?>
<li><a href=”/category/<?php echo createSlug($c); ?>”><?php echo $c; ?></a></li>
<?php endforeach; ?>
</ul>
</nav>
<div class=”search-box”>
<input type=”text” placeholder=”Search…” id=”siteSearch” onkeyup=”searchCats()”>
</div>
</div>
</header>
4. index.php (The Setup Page)
Use this to define or update your 20 categories.
<?php
if ($_SERVER[“REQUEST_METHOD”] == “POST”) {
$categories = array_filter(array_map(‘htmlspecialchars’, $_POST[‘categories’]));
file_put_contents(‘categories.json’, json_encode(array_values($categories), JSON_PRETTY_PRINT));
header(“Location: dashboard.php”);
}
$existing = file_exists(‘categories.json’) ? json_decode(file_get_contents(‘categories.json’), true) : [];
?>
<!DOCTYPE html>
<html>
<head><title>Initial Setup</title></head>
<body>
<?php include ‘header.php’; ?>
<div style=”max-width:600px; margin: 80px auto;”>
<h1>Setup 20 Categories</h1>
<form method=”POST”>
<?php for($i=0; $i<20; $i++): ?>
<input type=”text” name=”categories[]” value=”<?php echo $existing[$i] ?? ”; ?>” required style=”width:100%; margin-bottom:5px;”><br>
<?php endfor; ?>
<button type=”submit” style=”padding:10px 20px;”>Save Categories</button>
</form>
</div>
</body>
</html>
5. dashboard.php
Manage your articles and track progress.
<?php
include ‘header.php’;
$content = file_exists(‘content.json’) ? json_decode(file_get_contents(‘content.json’), true) : [];
?>
<div style=”max-width:800px; margin: 80px auto;”>
<h1>Content Dashboard</h1>
<table border=”1″ width=”100%” style=”border-collapse:collapse;”>
<tr><th>Category</th><th>Status</th><th>Action</th></tr>
<?php foreach($nav_categories as $cat): ?>
<tr>
<td><?php echo $cat; ?></td>
<td><?php echo isset($content[$cat]) ? ‘✅ Ready’ : ‘❌ Empty’; ?></td>
<td><a href=”edit_article.php?name=<?php echo urlencode($cat); ?>”>Edit Article</a></td>
</tr>
<?php endforeach; ?>
</table>
</div>
6. category.php (The Public Facing Page)
This template handles all 20 pages dynamically with SEO logic.
<?php
include_once ‘functions.php’;
$slug = $_GET[‘name’] ?? ”;
$categories = json_decode(file_get_contents(‘categories.json’), true);
$content_store = file_exists(‘content.json’) ? json_decode(file_get_contents(‘content.json’), true) : [];
$current_cat = “”;
foreach($categories as $c) {
if(createSlug($c) == $slug) { $current_cat = $c; break; }
}
if(!$current_cat) { die(“404 Page Not Found”); }
$page_data = $content_store[$current_cat] ?? [‘body’=>’Coming soon’, ‘meta_title’=>$current_cat, ‘meta_desc’=>”];
?>
<!DOCTYPE html>
<html>
<head>
<title><?php echo $page_data[‘meta_title’]; ?></title>
<meta name=”description” content=”<?php echo $page_data[‘meta_desc’]; ?>”>
</head>
<body>
<?php include ‘header.php’; ?>
<article style=”max-width:800px; margin: 100px auto;”>
<h1><?php echo $current_cat; ?></h1>
<div class=”content”><?php echo nl2br($page_data[‘body’]); ?></div>
</article>
</body>
</html>
7. sitemap.php
The XML generator for Google Search Console.
<?php
header(“Content-Type: application/xml”);
include_once ‘functions.php’;
$categories = json_decode(file_get_contents(‘categories.json’), true);
echo ‘<?xml version=”1.0″ encoding=”UTF-8″?><urlset xmlns=”http://www.sitemaps.org/schemas/sitemap/0.9″>’;
foreach($categories as $c) {
echo “<url><loc>https://yourdomain.com/category/”.createSlug($c).”</loc></url>”;
}
echo ‘</urlset>’;
?>
8. edit_article.php
The editor for saving body text and meta tags.
<?php
$cat_name = $_GET[‘name’] ?? ”;
$content_store = file_exists(‘content.json’) ? json_decode(file_get_contents(‘content.json’), true) : [];
if($_SERVER[‘REQUEST_METHOD’] == ‘POST’) {
$content_store[$cat_name] = [
‘body’ => $_POST[‘body’],
‘meta_title’ => $_POST[‘m_title’],
‘meta_desc’ => $_POST[‘m_desc’]
];
file_put_contents(‘content.json’, json_encode($content_store, JSON_PRETTY_PRINT));
header(“Location: dashboard.php”);
}
?>
This code provides a fully functional, SEO-optimized, data-driven website framework.
Discover more from NathanLegakis.com
Subscribe to get the latest posts sent to your email.
Leave a Reply