Development theme
File Structure (Themes)
The following is based on the initial files generated by "Create App":
/path/zb_users/theme/demoTheme
│ screenshot.png [Required] Thumbnail 320*240 pixels, landscape;
│ theme.xml [Required] Description file;
│ main.php [Optional] Application built-in management page, generated only if filled in during theme creation;
│ include.php [Optional] Application embedded page, generated only if filled in during theme creation;
│
├─compile [Deprecated] Old version z-blog used to place template compilation files, can be deleted directly;
├─include [Optional] Theme's own "File Modules", use {module:abc} to "embed and call" the abc.php file in this directory;
├─script [Optional] JS directory;
├─style [Required] Style directory, stylesheet and required images;
│ style.css [Required] Not limited to this filename, a theme can also have multiple styles (used independently);
│
├─css [Optional] Not automatically created, used for style content that should not be placed in the style folder;
└─template Used to store template files; it is recommended to prioritize the following 6 template files and their content;
index.php Homepage and list page
single.php Article page (single page)
search.php Search results page, uses index.php if not found
header.php Common header file
footer.php Common footer file
404.php Recommended to setMain Entry Templates
By default, the system will only attempt to directly call the four template files index.php, single.php, search.php, and 404.php (if they exist);
Other templates are combined into the "main template" through "embedded calls";
Example
Theoretically, the following example can be used as the basic structure for the four "main template" files; except for the "Your Code" section;
{template:header},{template:footer},{template:sidebar}are commonly used templates within the "Z-BlogPHP system", and{template:hero}can be freely named to split code for corresponding positions; ("Writing Templates - Embedded Calls")For details on "Template Description Information", "Embedded Calls", "Variable Output Tags", etc., please refer to: "Writing Templates"
{* Template Name: Homepage and list page * Template Type: index|list *}
<!-- ↑ "Template Description Information", including compatible "page types", placed on the first line of the template file -->
<!DOCTYPE html>
<html lang="{$language}"><!-- {$language} is a "Variable Output Tag" -->
<head>
{template:header}<!-- Common header file -->
</head>
<body class="{$type}"><!-- Also a "Variable Output Tag", corresponding to the Template Type above -->
{template:hero}
<!-- ↓Your Code↓ -->
<!-- ↓Your Code↓ -->
<div id="divNavBar">
<!-- Navigation "Module" Call -->
<ul>{module:navbar}</ul>
</div>
<div id="divMiddle">
<div id="divMain">List index or main content</div>
<!-- "Sidebar" Call -->
<div id="divSidebar">{template:sidebar}</div>
</div>
<!-- ↑Your Code↑ -->
<!-- ↑Your Code↑ -->
{template:footer}<!-- Common footer file -->
</body>
</html>Template Files and Default Mechanism
Due to the "reserved template" mechanism, if a theme does not provide a certain template file, the system will read and use it from
zb_system/defend/default; "View Online"Therefore, some template files that do not require custom content structure can be omitted, especially those related to "sidebar modules";
Common Template Files for Pages
| Template File | Description |
|---|---|
| header.php | Common header file |
| footer.php | Common footer file |
Templates Related to Homepage and List Pages
| Template File | Description |
|---|---|
| index.php | Main template file for homepage and list pages |
| post-multi.php | Excerpt article template |
| post-istop.php | Sticky article template |
| pagebar.php | Page number template |
Log/Standalone Page Related Templates
post-single.php
| Template File | Description |
|---|---|
| single.php | Main template file for article pages (single page) |
| Log page article template | |
| post-page.php | Standalone page template |
| comments.php | Comment section template |
| comment.php | Template for displaying each comment |
| commentpost.php | Template for comment submission form |
| commentpost-verify.php | Comment verification code template (added in 1.5) |
Sidebar Module Related Templates
Module display outer frame template
| Template File | Description |
|---|---|
| sidebar.php | Default sidebar template, custom sidebar2.php to sidebar9.php can be used for subsequent sidebar calls |
| module.php | Module display template, can define module title format, etc. The specific content format of the module is determined by the detail templates below |
Module content detail templates (version 1.5 and above)
| Template File | Description | Remarks (Default number of lines) |
|---|---|---|
| module-archives.php | Archive module | No limit |
| module-authors.php | Author list module | No limit |
| module-calendar.php | Calendar module | No limit |
| module-catalog.php | Category list module | No limit |
| module-navbar.php | Navigation bar module | No limit |
| module-statistics.php | Site information module | No limit |
| module-comments.php | Recent comments list module | 10 comments |
| module-previous.php | Recent posts list module | 10 posts |
| module-tags.php | Tag list module | 25 tags |
Writing Templates
Description Information (Optional)
Comment syntax within templates (recommended)
Place on the first line of the template file:
{* Template Name: "Description of template usage" *}Template type can also be declared (for "Main Entry Templates"):
{* Template Name: Homepage and list page * Template Type: index|list *}Note: The necessity of "description information" and "type declaration" is only reflected in the option output when
multiple "entry templates" are available for users to choose from for the same "page type", or whendifferent template files are created for different "page types". For the latter, you need to implement conditional calls yourself or guide users to select settings.Important: Within the
{}, there must be a space between the*and other content;- index Homepage - list List page - author - category - date - tag - single Single page (including articles and pages) - article - page - search Search - 404 404 - none Display hidden settings
Since version 1.7.0, template.json configuration is supported
template.json example: (Click to expand)
{ "id": "Theme ID", "templates": [ { "filename": "index", "type": "list", "name": "Auto template for list page" }, { "filename": "single", "type": "single", "name": "Auto template for article/single page" } ] }
Embedded Calls
Embed template files
{template:hearder}- Embeds the file content of the template file hearder.php."Embedded Call Example"
Embed module content
{module:navbar}- Embeds the "Navigation Bar" module.Note: Except for "File Modules" in the
includefolder, other modules are actually stored in the database. Also, it is not recommended to use "File Modules" as user modifications will be overwritten during theme updates."Modules", or "Sidebar Modules", generally refer to the items listed in "Backend Management" →
Module Management;navbaris the "filename" of the "Navigation Bar" module, and other "modules" are similar;
Template Tags
In the "Template File Example", two syntax tags, {$language} and {$type}, are used, called "Variable Output Tags" or "Template Tags". They are actually compiled into <?php echo $language;?> and <?php echo $type;?> to output the corresponding variable values;
In Z-BlogPHP templates, you can use {$var} and {$obj.a} to output "variables or object properties of text or numeric type". The latter is compiled into <?php echo $obj->a;?>;
Note:
Some tags can only be used on specific page types (
$typevalues) or in certain contexts;{module:navbar}can be considered a shorthand for{$modules["navbar"].Content};In addition to system tags, variables output as tags can be customized or modified through the "interface mechanism" or "native PHP syntax ①";
Using PHP in Templates
Before outputting corresponding content, you can use the following syntax to further process the data;
{php}
// Native PHP can be written here;
$myVar = "Variable value";
{/php}
<p>Output a custom variable: {$myVar}</p>
<p>The current Z-BlogPHP version is: {$version}</p>
//You can also use <?php ?> symbols within {php}{/php} for code highlighting
{php}<?php
//Native php code
?>{/php}Article link: http://docs.zbp.cool/zblogdocs/zblogapp/9.html
Helpful?
2025-10-09 14:07:45