Homework: WordPress File Structure & Template Hierarchy Diagrams
Assignment Objectives
- Create a comprehensive diagram of WordPress core file structure
- Map out the complete WordPress template hierarchy
- Understand how WordPress selects templates for different content types
- Document the relationship between files and their purposes
- Design visual aids that can serve as reference materials
- Practice technical documentation and diagramming skills
Assignment Overview
Your task is to create two comprehensive diagrams that will serve as reference materials for WordPress development: one showing the WordPress file structure and another illustrating the template hierarchy.
Important Note
1WordPress File Structure Diagram
Create a detailed diagram showing the WordPress core file structure. Your diagram should include:
Required Elements:
Reference Structure:
wordpress/ ├──index.php # Main entry point├──wp-config.php # Configuration file├──.htaccess # Apache server configuration├──wp-load.php # Bootstrap WordPress├──wp-blog-header.php # Loads WordPress environment├──wp-settings.php # WordPress settings├──xmlrpc.php # XML-RPC protocol support│ ├──wp-admin/ # Admin area files│ ├──admin.php│ ├──admin-ajax.php│ ├──css/│ ├──images/│ ├──includes/│ ├──js/│ └──index.php│ ├──wp-includes/ # Core WordPress files│ ├──blocks/ # Block editor blocks│ ├──css/ # Core CSS files│ ├──js/ # Core JavaScript files│ ├──fonts/ # Core fonts│ ├──rest-api/ # REST API endpoints│ ├──class-*.php # Core classes│ ├──functions.php # Core functions│ └──version.php # WordPress version│ └──wp-content/ # User content directory├──themes/ # Installed themes│ └──your-theme/│ ├──style.css # Theme stylesheet (required)│ ├──index.php # Main template (required)│ ├──functions.php # Theme functions│ ├──header.php # Header template│ ├──footer.php # Footer template│ ├──sidebar.php # Sidebar template│ ├──single.php # Single post template│ ├──page.php # Page template│ ├──archive.php # Archive template│ ├──assets/ # Theme assets│ └──template-parts/ # Template partials│ ├──plugins/ # Installed plugins│ └──your-plugin/│ ├──your-plugin.php # Main plugin file│ ├──includes/ # Plugin includes│ ├──admin/ # Admin functionality│ └──public/ # Public functionality│ ├──uploads/ # Media uploads│ └──2025/│ └──01/│ ├──image.jpg│ └──image-150x150.jpg│ └──languages/ # Translation files
2WordPress Template Hierarchy Diagram
Create a flowchart showing how WordPress selects templates for different types of content.
Required Coverage:
Template Hierarchy Flow:
graph TD
Start[Page Request] --> Type{Content Type?}
Type -->|Homepage| Home[Homepage]
Home --> FrontPage{Static Front Page?}
FrontPage -->|Yes| FP1[front-page.php]
FrontPage -->|No| HP1[home.php]
FP1 --> PageTemplate[page-{slug}.php]
HP1 --> Index[index.php]
PageTemplate --> PageID[page-{id}.php]
PageID --> Page[page.php]
Page --> Singular[singular.php]
Singular --> Index
Type -->|Single Post| Single[Single Post]
Single --> PostType{Post Type?}
PostType -->|Post| SP1[single-post.php]
PostType -->|Page| PG1[page-{slug}.php]
PostType -->|CPT| CPT1[single-{post-type}.php]
SP1 --> SP2[single.php]
PG1 --> PG2[page.php]
CPT1 --> SP2
SP2 --> Singular2[singular.php]
PG2 --> Singular2
Singular2 --> Index
Type -->|Archive| Archive[Archive]
Archive --> ArchiveType{Archive Type?}
ArchiveType -->|Category| Cat1[category-{slug}.php]
ArchiveType -->|Tag| Tag1[tag-{slug}.php]
ArchiveType -->|Author| Auth1[author-{nicename}.php]
Cat1 --> Cat2[category-{id}.php]
Cat2 --> Cat3[category.php]
Tag1 --> Tag2[tag-{id}.php]
Tag2 --> Tag3[tag.php]
Auth1 --> Auth2[author-{id}.php]
Auth2 --> Auth3[author.php]
Cat3 --> Arch[archive.php]
Tag3 --> Arch
Auth3 --> Arch
Arch --> Index
Type -->|Search| Search[search.php]
Type -->|404| Error[404.php]
Search --> Index
Error --> Index
Template Priority Examples:
Single Post for "hello-world"
- single-post-hello-world.phpHighest
- single-post.phpMedium
- single.phpMedium
- singular.phpLow
- index.phpFallback
Category Archive for "news" (ID: 5)
- category-news.phpHighest
- category-5.phpHigh
- category.phpMedium
- archive.phpLow
- index.phpFallback
3Create an Interactive Version
Build an interactive HTML/CSS/JavaScript version of your diagrams that allows users to explore the structure.
Requirements:
- Clickable elements that reveal more information
- Hover effects showing file purposes
- Search functionality to find specific templates
- Responsive design for mobile viewing
- Color coding for different file types
Example Interactive Tree Structure:
▶
wordpress/
▶
wp-content/
▶
themes/
• style.css - Main stylesheet
• index.php - Main template
• functions.php - Theme functions
▶
plugins/
• your-plugin.php - Main plugin file
▶
wp-admin/
• admin.php - Admin bootstrap
• admin-ajax.php - AJAX handler
Deliverables
📦 What to Submit:
-
File Structure Diagram:
- High-resolution image (PNG/SVG) or PDF
- Interactive HTML version (optional)
- Documentation explaining each major component
-
Template Hierarchy Diagram:
- Flowchart showing decision paths
- Examples for each content type
- Priority order documentation
-
README.md file including:
- How to read your diagrams
- Key insights you discovered
- Tools used to create the diagrams
- Any challenges faced and solutions
-
Code Repository (if interactive):
- HTML/CSS/JavaScript files
- Instructions for viewing/using
- Browser compatibility notes
Grading Rubric
| Criteria | Excellent (90-100%) | Good (70-89%) | Needs Improvement (Below 70%) |
|---|---|---|---|
| Accuracy | All file paths and template hierarchies are correct | Minor errors in paths or hierarchy | Significant errors or omissions |
| Completeness | Covers all required elements plus additional details | Covers all required elements | Missing required elements |
| Visual Design | Professional, clear, and visually appealing | Clear and organized | Difficult to read or understand |
| Documentation | Comprehensive explanations and insights | Good explanations provided | Limited or unclear documentation |
| Innovation | Creative presentation with interactive elements | Some creative elements | Basic presentation only |
🌟 Bonus Challenges (Extra Credit)
- Create a WordPress File Explorer:Build a web app that lets users explore the file structure interactively
- Template Hierarchy Quiz:Create an interactive quiz that tests knowledge of template selection
- Visual Template Selector:Build a tool that shows which template will be used based on URL input
- Comparison Chart:Create a chart comparing file structures across different WordPress versions
- Video Walkthrough:Record a 5-minute video explaining your diagrams
- Plugin Architecture:Add detailed plugin architecture patterns to your diagrams
- Theme Framework Comparison:Compare file structures of popular theme frameworks
Recommended Tools & Resources
Diagramming Tools:
- Draw.io- Free online diagramming
- Lucidchart- Professional diagrams
- Mermaid Live Editor- Code-based diagrams
- Figma- Design and prototyping
- Excalidraw- Hand-drawn style diagrams
Reference Documentation:
- Official Template Hierarchy Documentation
- Organizing Theme Files
- Interactive Template Hierarchy
- WordPress Files Reference
Code Examples:
// Example: Creating an interactive file tree
class FileTreeExplorer {
constructor(containerId) {
this.container = document.getElementById(containerId);
this.fileStructure = this.getWordPressStructure();
this.render();
}
getWordPressStructure() {
return {
'wordpress': {
type: 'folder',
children: {
'wp-admin': {
type: 'folder',
description: 'WordPress admin area files',
children: {
'admin.php': {
type: 'file',
description: 'Main admin bootstrap file'
},
'admin-ajax.php': {
type: 'file',
description: 'Handles AJAX requests'
}
}
},
'wp-content': {
type: 'folder',
description: 'User content directory',
children: {
'themes': {
type: 'folder',
description: 'WordPress themes',
children: {}
},
'plugins': {
type: 'folder',
description: 'WordPress plugins',
children: {}
}
}
}
}
}
};
}
render() {
const html = this.renderNode(this.fileStructure);
this.container.innerHTML = html;
this.attachEventListeners();
}
renderNode(node, level = 0) {
let html = '';
for (const [name, data] of Object.entries(node)) {
const indent = ' '.repeat(level);
const icon = data.type === 'folder' ? '📁' : '📄';
html += `
<div class="tree-item" data-level="${level}">
${indent}${icon} ${name}
${data.description ? `<span class="description">${data.description}</span>` : ''}
${data.children ? this.renderNode(data.children, level + 1) : ''}
</div>
`;
}
return html;
}
attachEventListeners() {
// Add click handlers for expanding/collapsing
this.container.querySelectorAll('.tree-item').forEach(item => {
item.addEventListener('click', (e) => {
e.stopPropagation();
item.classList.toggle('expanded');
});
});
}
}
// Initialize the explorer
new FileTreeExplorer('wordpress-structure');
<?php
// Example: Template Hierarchy Resolver
class TemplateHierarchyResolver {
public function get_template_hierarchy($query_type, $specifics = array()) {
$templates = array();
switch ($query_type) {
case 'single_post':
$post_type = $specifics['post_type'] ?? 'post';
$post_slug = $specifics['slug'] ?? '';
if ($post_type === 'post') {
if ($post_slug) {
$templates[] = "single-post-{$post_slug}.php";
}
$templates[] = 'single-post.php';
}
$templates[] = "single-{$post_type}.php";
$templates[] = 'single.php';
$templates[] = 'singular.php';
break;
case 'category':
$slug = $specifics['slug'] ?? '';
$id = $specifics['id'] ?? '';
if ($slug) {
$templates[] = "category-{$slug}.php";
}
if ($id) {
$templates[] = "category-{$id}.php";
}
$templates[] = 'category.php';
$templates[] = 'archive.php';
break;
case 'page':
$slug = $specifics['slug'] ?? '';
$id = $specifics['id'] ?? '';
$template = $specifics['template'] ?? '';
if ($template) {
$templates[] = $template;
}
if ($slug) {
$templates[] = "page-{$slug}.php";
}
if ($id) {
$templates[] = "page-{$id}.php";
}
$templates[] = 'page.php';
$templates[] = 'singular.php';
break;
}
// Always fall back to index.php
$templates[] = 'index.php';
return $templates;
}
public function visualize_hierarchy($templates) {
echo '<div class="template-hierarchy">';
foreach ($templates as $priority => $template) {
$exists = file_exists(get_template_directory() . '/' . $template);
$class = $exists ? 'exists' : 'missing';
echo sprintf(
'<div class="template-item %s">
<span class="priority">%d</span>
<span class="filename">%s</span>
<span class="status">%s</span>
</div>',
$class,
$priority + 1,
$template,
$exists ? '✓' : '✗'
);
}
echo '</div>';
}
}
// Usage
$resolver = new TemplateHierarchyResolver();
$hierarchy = $resolver->get_template_hierarchy('single_post', [
'post_type' => 'post',
'slug' => 'hello-world'
]);
$resolver->visualize_hierarchy($hierarchy);
?>
Pro Tips for Success
Tips from Previous Students
Final Submission Checklist
Need Help?
Support Resources