Mastering XooPress Themes
From Basic Templates to Advanced Child Themes
XooPress adopts the WordPress-style theming system, making it instantly familiar to millions of developers and designers. Whether you're building your first theme or creating advanced child themes, this guide covers everything you need to know.
π Understanding Theme Structure
Every XooPress theme lives in the /themes/ directory. Here's what a complete theme looks like:
themes/my-theme/
βββ style.css # Theme metadata (required)
βββ index.php # Main template (required fallback)
βββ header.php # Header template part
βββ footer.php # Footer template part
βββ sidebar.php # Sidebar template part
βββ functions.php # Theme functions (loaded on every request)
βββ screenshot.png # Admin preview image (880x660 recommended)
βββ theme.json # Advanced configuration
βββ assets/ # Static assets (CSS, JS, images)
β βββ css/
β β βββ main.css
β βββ js/
β β βββ main.js
β βββ images/
β βββ logo.svg
βββ templates/ # Alternative template directory
βββ page-home.php
π¨ The Heart of Your Theme: style.css
The style.css file serves two purposes: it contains your theme's metadata AND your CSS styles. The header block follows the WordPress convention:
/*
Theme Name: My Awesome Theme
Theme URI: https://example.com/
Author: Your Name
Author URI: https://example.com/
Description: A modern, responsive theme for XooPress
Version: 1.0.0
License: GPL-3.0-or-later
License URI: https://www.gnu.org/licenses/gpl-3.0.html
Template: parent-theme-dir /* For child themes only */
Tags: one-column, two-columns, right-sidebar, custom-header
Text Domain: my-theme
*/
/* Your CSS starts here */
:root {
--primary-color: #4f46e5;
--text-color: #1f2937;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
color: var(--text-color);
line-height: 1.6;
}
πΌοΈ Essential Template Files
header.php
<!DOCTYPE html>
<html <?= $htmlAttrs ?? 'lang="en"' ?>>
<head>
<meta charset="<?= $charset ?? 'UTF-8' ?>">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= !empty($title) ? htmlspecialchars($title) . ' - ' : '' ?><?= htmlspecialchars($siteName ?? 'XooPress') ?></title>
<link rel="stylesheet" href="<?= $theme->getStylesheetUrl() ?>">
<?php if (!empty($head)) echo $head; ?>
</head>
<body>
<header class="site-header">
<div class="container">
<h1><a href="<?= $homeUrl ?? '/' ?>"><?= htmlspecialchars($siteName ?? 'XooPress') ?></a></h1>
</div>
</header>
<main class="site-content">
<div class="container">
index.php
<?= $theme->getHeader() ?>
<div class="content-area">
<?php if (!empty($posts)): ?>
<?php foreach ($posts as $post): ?>
<article class="post">
<h2><a href="/posts/<?= $post['id'] ?>"><?= htmlspecialchars($post['title']) ?></a></h2>
<div class="content">
<?= $post['rendered_content'] ?? $post['content'] ?>
</div>
</article>
<?php endforeach; ?>
<?php endif; ?>
</div>
<?= $theme->getFooter() ?>
footer.php
</div><!-- .container -->
</main>
<footer>
<p>© <?= date('Y') ?> <?= htmlspecialchars($siteName ?? 'XooPress') ?></p>
</footer>
</body>
</html>
π§ Available Template Variables
When building themes, you have access to these variables in your templates:
| Variable | Description |
|---|---|
$theme |
ThemeManager instance with helper methods |
$activeTheme |
Active (parent) theme data array |
$childTheme |
Child theme data array (or null) |
$posts |
Array of post records from the controller |
$post |
Single post record (on single post pages) |
$siteName |
Site name from database settings |
$siteDescription |
Site description from database settings |
π§© Template Parts System
XooPress provides a WordPress-like template part system for organizing reusable components:
<?php
// In any template file:
$theme->getHeader(); // Includes header.php
$theme->getFooter(); // Includes footer.php
$theme->getSidebar(); // Includes sidebar.php
$theme->getTemplatePart('nav', 'main'); // Includes nav-main.php
$theme->getTemplatePart('loop'); // Includes loop.php
?>
Template parts follow the child-parent hierarchy, searching in this order:
- Child theme
templates/directory - Parent theme
templates/directory - Child theme root directory
- Parent theme root directory
πΆ Child Themes - The Smart Way to Customize
Child themes are the professional way to customize an existing theme without losing your changes when the parent theme updates.
- Safe Updates β Update the parent theme without losing customizations
- Minimal Files β Only include the files you want to override
- Clean Separation β Keep custom code separate from the parent theme
Creating a Child Theme in 3 Steps
Step 1: Create a directory in /themes/
themes/my-child-theme/
Step 2: Add a style.css file with the Template: header pointing to the parent theme:
/* Theme Name: My Child Theme Theme URI: https://example.com/ Author: Your Name Description: A child theme of XooPress Lite Version: 1.0.0 Template: xoopress-lite Text Domain: my-child */
Template: header must exactly match the directory name of the parent theme (case-sensitive)!
Step 3: Activate your child theme at /admin/themes
What Gets Overridden?
Any file in the child theme with the same name as a parent theme file will override it:
themes/xoopress-lite/ # Parent theme βββ header.php # Default header βββ footer.php # Default footer βββ index.php # Default index βββ sidebar.php # Default sidebar themes/my-child/ # Child theme βββ style.css # Required βββ header.php # Overrides parent's header.php βββ custom-page.php # New template (parent doesn't have)
In this example, only header.php is overridden. The footer, index, and sidebar come from the parent theme.
functions.php in Child Themes
Both parent and child functions.php files are loaded. The parent loads first, then the child:
// themes/my-child/functions.php
<?php
// This runs AFTER the parent theme's functions.php
// Add custom styles
$theme->addAsset('css', 'custom.css');
// Override parent settings
$theme->setSetting('layout', 'full-width');
πΎ Theme Settings
Store per-theme settings in the database using simple key-value pairs:
<?php
// In your theme's functions.php or any template:
$theme->setSetting('layout', 'full-width');
$theme->setSetting('primary_color', '#4f46e5');
$theme->setSetting('sidebar_position', 'right');
// Retrieve settings with defaults
$layout = $theme->getSetting('layout', 'default');
$color = $theme->getSetting('primary_color', '#333');
?>
Settings are stored in the xp_theme_settings database table and persist across theme switches.
π¦ Theme Management via Admin
The admin panel at /admin/themes provides complete theme management:
Activate
Click "Activate" under any installed theme to apply it immediately to your public site.
Upload
Upload a .zip file containing your theme. The system extracts it to /themes/ automatically.
Delete
Delete inactive themes directly from the admin panel. (Active themes cannot be deleted.)
Theme ZIP Requirements
When uploading a theme, your ZIP file must follow this structure:
my-theme.zip
βββ my-theme/ # Must contain a directory
βββ style.css # Required - must have Theme Name
βββ index.php # Required - fallback template
βββ header.php # Optional
βββ footer.php # Optional
βββ sidebar.php # Optional
βββ functions.php # Optional
βββ screenshot.png # Optional - admin preview (880x660)
βββ theme.json # Optional - advanced config
βββ assets/ # Optional - static assets
βββ css/
βββ js/
βββ images/
π Theme States
| State | Description |
|---|---|
| β Active | Currently in use on the public site |
| β Inactive | Installed but not active |
π― Real-World Examples
Example 1: Simple Blog Theme
themes/my-blog/ βββ style.css βββ index.php βββ header.php βββ footer.php βββ single.php # Custom single post view
Example 2: Child Theme Overriding Header Only
themes/custom-header/ βββ style.css (Template: xoopress-lite) βββ header.php (Only this file is overridden)
Example 3: Complete Custom Theme
themes/premium-theme/
βββ style.css
βββ index.php
βββ header.php
βββ footer.php
βββ sidebar.php
βββ functions.php
βββ theme.json
βββ screenshot.png
βββ assets/
β βββ css/main.css
β βββ js/main.js
β βββ images/logo.svg
βββ templates/
βββ page-home.php
βββ page-about.php
βββ single-portfolio.php
π Next Steps
- π Read the Building Your First Module guide for backend development
- π¨ Explore the Theme Manager to see available themes
- π§ Check out Site Settings to configure your site
- π Create your first post using one of the 4 editor types
- Always include a fallback
index.phpβ it's the ultimate safety net - Use
$post['rendered_content'] ?? $post['content']for backward compatibility - Test your theme with both XooPress Lite and XooPress Dark
- Make your theme responsive β test on mobile devices
- Include a
screenshot.png(880x660) for better admin presentation
Happy theming with XooPress! π¨ Whether you're building from scratch or creating child themes, the WordPress-style system makes it familiar and powerful.